Merge lp:~widelands-dev/widelands/soldier_refactoring into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7879
Proposed branch: lp:~widelands-dev/widelands/soldier_refactoring
Merge into: lp:widelands
Diff against target: 2723 lines (+597/-620)
37 files modified
data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua (+1/-1)
data/tribes/buildings/trainingsites/atlanteans/labyrinth/init.lua (+5/-5)
data/tribes/buildings/trainingsites/barbarians/trainingcamp/init.lua (+13/-13)
data/tribes/buildings/trainingsites/empire/trainingcamp/init.lua (+17/-17)
data/tribes/scripting/help/building_help.lua (+6/-6)
data/tribes/workers/atlanteans/soldier/init.lua (+25/-30)
data/tribes/workers/barbarians/soldier/init.lua (+25/-31)
data/tribes/workers/empire/soldier/init.lua (+25/-31)
src/ai/defaultai.cc (+17/-17)
src/logic/findbob.cc (+1/-1)
src/logic/game.cc (+3/-3)
src/logic/game.h (+1/-1)
src/logic/map_objects/map_object.cc (+1/-1)
src/logic/map_objects/map_object.h (+2/-1)
src/logic/map_objects/tribes/battle.cc (+2/-2)
src/logic/map_objects/tribes/militarysite.cc (+11/-11)
src/logic/map_objects/tribes/production_program.cc (+28/-27)
src/logic/map_objects/tribes/requirements.cc (+29/-15)
src/logic/map_objects/tribes/requirements.h (+1/-1)
src/logic/map_objects/tribes/soldier.cc (+116/-150)
src/logic/map_objects/tribes/soldier.h (+60/-71)
src/logic/map_objects/tribes/training_attribute.h (+8/-6)
src/logic/map_objects/tribes/trainingsite.cc (+47/-47)
src/logic/map_objects/tribes/trainingsite.h (+18/-18)
src/logic/map_objects/tribes/warehouse.cc (+2/-2)
src/logic/player.cc (+1/-2)
src/logic/player.h (+1/-1)
src/logic/playercommand.cc (+6/-7)
src/logic/playercommand.h (+4/-3)
src/logic/widelands.h (+4/-4)
src/map_io/map_buildingdata_packet.cc (+30/-7)
src/scripting/lua_map.cc (+70/-70)
src/scripting/lua_map.h (+5/-5)
src/wui/soldierlist.cc (+4/-4)
src/wui/trainingsitewindow.cc (+0/-1)
test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua (+6/-6)
test/maps/lua_testsuite.wmf/scripting/warehouse.lua (+2/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/soldier_refactoring
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+286753@code.launchpad.net

Commit message

Some refactoring for the Soldier code:
- Refactored the battle attributes in SoldierDescr (health, attack, defense, evade) into a nice Lua table and struct.
- Made member variables in SolderDescr private.
- Renamed all instances of "hp" and "hitpoints" to "health" for consistency.
- TrainingAttribute is now an enum class with consistent saveloading datatype.

Description of the change

The Lua code for the soldier descriptions was still a holdover from the old conf file format. I have now created some nicer data structures and done some code refactoring (see commit message).

I'd like this in Build 19, because it will be a pain for modders otherwise.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

Running 'bzr pull --overwrite' failed. Output:

ssh_exchange_identification: Connection closed by remote host
ConnectionReset reading response for 'BzrDir.open_2.1', retrying
ssh_exchange_identification: Connection closed by remote host
bzr: ERROR: Connection closed: Unexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.
Using saved parent location: bzr+ssh://bazaar.launchpad.net/~widelands-dev/widelands/soldier_refactoring/

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 759. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/110812226.
Appveyor build 605. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_soldier_refactoring-605.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 765. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/111151710.
Appveyor build 611. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_soldier_refactoring-611.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 799. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/113180904.
Appveyor build 645. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_soldier_refactoring-645.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 821. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/114843776.
Appveyor build 645. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_soldier_refactoring-645.

Revision history for this message
TiborB (tiborb95) wrote :

Code LGTM, though there was a lot of numbers and I did not compare old vs new ones

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

Thanks for the review :)

I double-checked the numbers again, so I think we're good.

@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-01-28 05:24:34 +0000
3+++ data/campaigns/tutorial02_warfare.wmf/scripting/texts.lua 2016-03-09 16:59:37 +0000
4@@ -31,7 +31,7 @@
5 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.]]) ..
6 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:]])
7 ) ..
8- rt("image=tribes/workers/barbarians/soldier/hp_level0.png", h2(_"Health:"))..
9+ rt("image=tribes/workers/barbarians/soldier/health_level0.png", h2(_"Health:"))..
10 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.]])) ..
11 rt("image=tribes/workers/barbarians/soldier/attack_level0.png", h2(_"Attack:")) ..
12 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.]])) ..
13
14=== modified file 'data/tribes/buildings/trainingsites/atlanteans/labyrinth/init.lua'
15--- data/tribes/buildings/trainingsites/atlanteans/labyrinth/init.lua 2016-02-17 15:29:52 +0000
16+++ data/tribes/buildings/trainingsites/atlanteans/labyrinth/init.lua 2016-03-09 16:59:37 +0000
17@@ -69,7 +69,7 @@
18 "shield_advanced"
19 }
20 },
21- ["soldier hp"] = {
22+ ["soldier health"] = {
23 min_level = 0,
24 max_level = 0,
25 food = {
26@@ -119,15 +119,15 @@
27 "train=soldier defense 1 2"
28 }
29 },
30- upgrade_soldier_hp_0 = {
31+ upgrade_soldier_health_0 = {
32 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
33 descname = _"upgrading soldier health from level 0 to level 1",
34 actions = {
35- "check_soldier=soldier hp 0", -- Fails when aren't any soldier of level 0 hp
36+ "check_soldier=soldier health 0", -- Fails when aren't any soldier of level 0 health
37 "sleep=30000",
38- "check_soldier=soldier hp 0", -- Because the soldier can be expelled by the player
39+ "check_soldier=soldier health 0", -- Because the soldier can be expelled by the player
40 "consume=smoked_fish,smoked_meat:2 tabard_golden",
41- "train=soldier hp 0 1"
42+ "train=soldier health 0 1"
43 }
44 },
45 upgrade_soldier_evade_0 = {
46
47=== modified file 'data/tribes/buildings/trainingsites/barbarians/trainingcamp/init.lua'
48--- data/tribes/buildings/trainingsites/barbarians/trainingcamp/init.lua 2016-01-02 21:39:43 +0000
49+++ data/tribes/buildings/trainingsites/barbarians/trainingcamp/init.lua 2016-03-09 16:59:37 +0000
50@@ -82,7 +82,7 @@
51 "ax_warriors"
52 }
53 },
54- ["soldier hp"] = {
55+ ["soldier health"] = {
56 min_level = 0,
57 max_level = 2,
58 food = {
59@@ -160,37 +160,37 @@
60 "train=soldier attack 4 5"
61 }
62 },
63- upgrade_soldier_hp_0 = {
64+ upgrade_soldier_health_0 = {
65 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
66 descname = _"upgrading soldier health from level 0 to level 1",
67 actions = {
68- "check_soldier=soldier hp 0",
69+ "check_soldier=soldier health 0",
70 "sleep=30000",
71- "check_soldier=soldier hp 0",
72+ "check_soldier=soldier health 0",
73 "consume=helmet barbarians_bread,fish,meat",
74- "train=soldier hp 0 1"
75+ "train=soldier health 0 1"
76 }
77 },
78- upgrade_soldier_hp_1 = {
79+ upgrade_soldier_health_1 = {
80 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
81 descname = _"upgrading soldier health from level 1 to level 2",
82 actions = {
83- "check_soldier=soldier hp 1",
84+ "check_soldier=soldier health 1",
85 "sleep=30000",
86- "check_soldier=soldier hp 1",
87+ "check_soldier=soldier health 1",
88 "consume=helmet_mask fish,meat barbarians_bread",
89- "train=soldier hp 1 2"
90+ "train=soldier health 1 2"
91 }
92 },
93- upgrade_soldier_hp_2 = {
94+ upgrade_soldier_health_2 = {
95 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
96 descname = _"upgrading soldier health from level 2 to level 3",
97 actions = {
98- "check_soldier=soldier hp 2",
99+ "check_soldier=soldier health 2",
100 "sleep=30000",
101- "check_soldier=soldier hp 2",
102+ "check_soldier=soldier health 2",
103 "consume=helmet_warhelm fish,meat:2 barbarians_bread",
104- "train=soldier hp 2 3"
105+ "train=soldier health 2 3"
106 }
107 },
108 },
109
110=== modified file 'data/tribes/buildings/trainingsites/empire/trainingcamp/init.lua'
111--- data/tribes/buildings/trainingsites/empire/trainingcamp/init.lua 2016-01-02 21:39:43 +0000
112+++ data/tribes/buildings/trainingsites/empire/trainingcamp/init.lua 2016-03-09 16:59:37 +0000
113@@ -75,7 +75,7 @@
114 "spear_war"
115 }
116 },
117- ["soldier hp"] = {
118+ ["soldier health"] = {
119 min_level = 0,
120 max_level = 3,
121 food = {
122@@ -143,48 +143,48 @@
123 "train=soldier attack 3 4"
124 }
125 },
126- upgrade_soldier_hp_0 = {
127+ upgrade_soldier_health_0 = {
128 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
129 descname = _"upgrading soldier health from level 0 to level 1",
130 actions = {
131- "check_soldier=soldier hp 0",
132+ "check_soldier=soldier health 0",
133 "sleep=30000",
134- "check_soldier=soldier hp 0",
135+ "check_soldier=soldier health 0",
136 "consume=armor_helmet empire_bread,fish,meat",
137- "train=soldier hp 0 1"
138+ "train=soldier health 0 1"
139 }
140 },
141- upgrade_soldier_hp_1 = {
142+ upgrade_soldier_health_1 = {
143 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
144 descname = _"upgrading soldier health from level 1 to level 2",
145 actions = {
146- "check_soldier=soldier hp 1",
147+ "check_soldier=soldier health 1",
148 "sleep=30000",
149- "check_soldier=soldier hp 1",
150+ "check_soldier=soldier health 1",
151 "consume=armor empire_bread fish,meat",
152- "train=soldier hp 1 2"
153+ "train=soldier health 1 2"
154 }
155 },
156- upgrade_soldier_hp_2 = {
157+ upgrade_soldier_health_2 = {
158 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
159 descname = _"upgrading soldier health from level 2 to level 3",
160 actions = {
161- "check_soldier=soldier hp 2",
162+ "check_soldier=soldier health 2",
163 "sleep=30000",
164- "check_soldier=soldier hp 2",
165+ "check_soldier=soldier health 2",
166 "consume=armor_chain empire_bread:2 fish,meat:2",
167- "train=soldier hp 2 3"
168+ "train=soldier health 2 3"
169 }
170 },
171- upgrade_soldier_hp_3 = {
172+ upgrade_soldier_health_3 = {
173 -- TRANSLATORS: Completed/Skipped/Did not start upgrading ... because ...
174 descname = _"upgrading soldier health from level 3 to level 4",
175 actions = {
176- "check_soldier=soldier hp 3",
177+ "check_soldier=soldier health 3",
178 "sleep=30000",
179- "check_soldier=soldier hp 3",
180+ "check_soldier=soldier health 3",
181 "consume=armor_gilded empire_bread:2 fish,meat:2",
182- "train=soldier hp 3 4"
183+ "train=soldier health 3 4"
184 }
185 },
186 },
187
188=== modified file 'data/tribes/scripting/help/building_help.lua'
189--- data/tribes/scripting/help/building_help.lua 2016-02-27 08:43:39 +0000
190+++ data/tribes/scripting/help/building_help.lua 2016-03-09 16:59:37 +0000
191@@ -373,18 +373,18 @@
192 --
193 function building_help_dependencies_training(tribe, building_description)
194 local result = ""
195- if (building_description.max_hp and building_description.min_hp) then
196+ if (building_description.max_health and building_description.min_health) then
197 result = result .. rt(h2(_"Health Training"))
198 result = result .. rt(p(_"Trains ‘Health’ from %1% up to %2%":
199- bformat(building_description.min_hp, building_description.max_hp+1)))
200+ bformat(building_description.min_health, building_description.max_health+1)))
201 result = result .. rt(h3(_"Soldiers:"))
202 result = result ..
203 dependencies_basic({
204- "tribes/workers/" .. tribe.name .. "/soldier/hp_level" .. building_description.min_hp .. ".png",
205+ "tribes/workers/" .. tribe.name .. "/soldier/health_level" .. building_description.min_health .. ".png",
206 building_description.icon_name,
207- "tribes/workers/" .. tribe.name .. "/soldier/hp_level" .. (building_description.max_hp + 1) ..".png"})
208- result = result .. dependencies_training_food(building_description.food_hp)
209- result = result .. dependencies_training_weapons(building_description.weapons_hp)
210+ "tribes/workers/" .. tribe.name .. "/soldier/health_level" .. (building_description.max_health + 1) ..".png"})
211+ result = result .. dependencies_training_food(building_description.food_health)
212+ result = result .. dependencies_training_weapons(building_description.weapons_health)
213 end
214 if (building_description.max_attack and building_description.min_attack) then
215 result = result .. rt(h2(_"Attack Training"))
216
217=== renamed file 'data/tribes/workers/atlanteans/soldier/hp_level0.png' => 'data/tribes/workers/atlanteans/soldier/health_level0.png'
218=== renamed file 'data/tribes/workers/atlanteans/soldier/hp_level1.png' => 'data/tribes/workers/atlanteans/soldier/health_level1.png'
219=== modified file 'data/tribes/workers/atlanteans/soldier/init.lua'
220--- data/tribes/workers/atlanteans/soldier/init.lua 2015-12-11 16:54:00 +0000
221+++ data/tribes/workers/atlanteans/soldier/init.lua 2016-03-09 16:59:37 +0000
222@@ -77,37 +77,32 @@
223
224 animations = animations,
225
226- max_hp_level = 1,
227- max_attack_level = 4,
228- max_defense_level = 2,
229- max_evade_level = 2,
230-
231- -- Initial values and per level increments.
232- hp = 13500,
233- hp_incr_per_level = 4000,
234+ -- Battle attributes - initial values and per level increase
235+ health = {
236+ max_level = 1,
237+ base = 13500,
238+ increase_per_level = 4000,
239+ pictures = path.list_files(dirname .. "health_level?.png"),
240+ },
241 attack = {
242- minimum = 1200,
243- maximum = 1600
244- },
245- attack_incr_per_level = 800,
246- defense = 6,
247- defense_incr_per_level = 8,
248- evade = 30,
249- evade_incr_per_level = 17,
250-
251- hp_level_0_pic = dirname .. "hp_level0.png",
252- hp_level_1_pic = dirname .. "hp_level1.png",
253- evade_level_0_pic = dirname .. "evade_level0.png",
254- evade_level_1_pic = dirname .. "evade_level1.png",
255- evade_level_2_pic = dirname .. "evade_level2.png",
256- attack_level_0_pic = dirname .. "attack_level0.png",
257- attack_level_1_pic = dirname .. "attack_level1.png",
258- attack_level_2_pic = dirname .. "attack_level2.png",
259- attack_level_3_pic = dirname .. "attack_level3.png",
260- attack_level_4_pic = dirname .. "attack_level4.png",
261- defense_level_0_pic = dirname .. "defense_level0.png",
262- defense_level_1_pic = dirname .. "defense_level1.png",
263- defense_level_2_pic = dirname .. "defense_level2.png",
264+ max_level = 4,
265+ base = 1200,
266+ maximum = 1600,
267+ increase_per_level = 800,
268+ pictures = path.list_files(dirname .. "attack_level?.png"),
269+ },
270+ defense = {
271+ max_level = 2,
272+ base = 6,
273+ increase_per_level = 8,
274+ pictures = path.list_files(dirname .. "defense_level?.png"),
275+ },
276+ evade = {
277+ max_level = 2,
278+ base = 30,
279+ increase_per_level = 17,
280+ pictures = path.list_files(dirname .. "evade_level?.png"),
281+ },
282
283 -- Random animations for battle
284 -- TODO(GunChleoc): Make more animations to use the random function
285
286=== renamed file 'data/tribes/workers/barbarians/soldier/hp_level0.png' => 'data/tribes/workers/barbarians/soldier/health_level0.png'
287=== renamed file 'data/tribes/workers/barbarians/soldier/hp_level1.png' => 'data/tribes/workers/barbarians/soldier/health_level1.png'
288=== renamed file 'data/tribes/workers/barbarians/soldier/hp_level2.png' => 'data/tribes/workers/barbarians/soldier/health_level2.png'
289=== renamed file 'data/tribes/workers/barbarians/soldier/hp_level3.png' => 'data/tribes/workers/barbarians/soldier/health_level3.png'
290=== modified file 'data/tribes/workers/barbarians/soldier/init.lua'
291--- data/tribes/workers/barbarians/soldier/init.lua 2016-02-20 08:51:41 +0000
292+++ data/tribes/workers/barbarians/soldier/init.lua 2016-03-09 16:59:37 +0000
293@@ -76,38 +76,32 @@
294
295 animations = animations,
296
297- max_hp_level = 3,
298- max_attack_level = 5,
299- max_defense_level = 0,
300- max_evade_level = 2,
301-
302- -- initial values and per level increasements
303- hp = 13000,
304- hp_incr_per_level = 2800,
305+ -- Battle attributes - initial values and per level increase
306+ health = {
307+ max_level = 3,
308+ base = 13000,
309+ increase_per_level = 2800,
310+ pictures = path.list_files(dirname .. "health_level?.png"),
311+ },
312 attack = {
313- minimum = 1200,
314- maximum = 1600
315- },
316- attack_incr_per_level = 850,
317- defense = 3,
318- defense_incr_per_level = 4,
319- evade = 25,
320- evade_incr_per_level = 15,
321-
322- hp_level_0_pic = dirname .. "hp_level0.png",
323- hp_level_1_pic = dirname .. "hp_level1.png",
324- hp_level_2_pic = dirname .. "hp_level2.png",
325- hp_level_3_pic = dirname .. "hp_level3.png",
326- evade_level_0_pic = dirname .. "evade_level0.png",
327- evade_level_1_pic = dirname .. "evade_level1.png",
328- evade_level_2_pic = dirname .. "evade_level2.png",
329- attack_level_0_pic = dirname .. "attack_level0.png",
330- attack_level_1_pic = dirname .. "attack_level1.png",
331- attack_level_2_pic = dirname .. "attack_level2.png",
332- attack_level_3_pic = dirname .. "attack_level3.png",
333- attack_level_4_pic = dirname .. "attack_level4.png",
334- attack_level_5_pic = dirname .. "attack_level5.png",
335- defense_level_0_pic = dirname .. "defense_level0.png",
336+ max_level = 5,
337+ base = 1200,
338+ maximum = 1600,
339+ increase_per_level = 850,
340+ pictures = path.list_files(dirname .. "attack_level?.png"),
341+ },
342+ defense = {
343+ max_level = 0,
344+ base = 3,
345+ increase_per_level = 4,
346+ pictures = path.list_files(dirname .. "defense_level?.png"),
347+ },
348+ evade = {
349+ max_level = 2,
350+ base = 25,
351+ increase_per_level = 15,
352+ pictures = path.list_files(dirname .. "evade_level?.png"),
353+ },
354
355 -- Random animations for battle
356 attack_success_w = {
357
358=== renamed file 'data/tribes/workers/empire/soldier/hp_level0.png' => 'data/tribes/workers/empire/soldier/health_level0.png'
359=== renamed file 'data/tribes/workers/empire/soldier/hp_level1.png' => 'data/tribes/workers/empire/soldier/health_level1.png'
360=== renamed file 'data/tribes/workers/empire/soldier/hp_level2.png' => 'data/tribes/workers/empire/soldier/health_level2.png'
361=== renamed file 'data/tribes/workers/empire/soldier/hp_level3.png' => 'data/tribes/workers/empire/soldier/health_level3.png'
362=== renamed file 'data/tribes/workers/empire/soldier/hp_level4.png' => 'data/tribes/workers/empire/soldier/health_level4.png'
363=== modified file 'data/tribes/workers/empire/soldier/init.lua'
364--- data/tribes/workers/empire/soldier/init.lua 2015-12-11 16:54:00 +0000
365+++ data/tribes/workers/empire/soldier/init.lua 2016-03-09 16:59:37 +0000
366@@ -77,38 +77,32 @@
367
368 animations = animations,
369
370- max_hp_level = 4,
371- max_attack_level = 4,
372- max_defense_level = 0,
373- max_evade_level = 2,
374-
375- -- initial values and per level increasements
376- hp = 13000,
377- hp_incr_per_level = 2100,
378+ -- Battle attributes - initial values and per level increase
379+ health = {
380+ max_level = 4,
381+ base = 13000,
382+ increase_per_level = 2100,
383+ pictures = path.list_files(dirname .. "health_level?.png"),
384+ },
385 attack = {
386- minimum = 1300,
387- maximum = 1500
388- },
389- attack_incr_per_level = 800,
390- defense = 5,
391- defense_incr_per_level = 5,
392- evade = 30,
393- evade_incr_per_level = 16,
394-
395- hp_level_0_pic = dirname .. "hp_level0.png",
396- hp_level_1_pic = dirname .. "hp_level1.png",
397- hp_level_2_pic = dirname .. "hp_level2.png",
398- hp_level_3_pic = dirname .. "hp_level3.png",
399- hp_level_4_pic = dirname .. "hp_level4.png",
400- evade_level_0_pic = dirname .. "evade_level0.png",
401- evade_level_1_pic = dirname .. "evade_level1.png",
402- evade_level_2_pic = dirname .. "evade_level2.png",
403- attack_level_0_pic = dirname .. "attack_level0.png",
404- attack_level_1_pic = dirname .. "attack_level1.png",
405- attack_level_2_pic = dirname .. "attack_level2.png",
406- attack_level_3_pic = dirname .. "attack_level3.png",
407- attack_level_4_pic = dirname .. "attack_level4.png",
408- defense_level_0_pic = dirname .. "defense_level0.png",
409+ max_level = 4,
410+ base = 1300,
411+ maximum = 1500,
412+ increase_per_level = 800,
413+ pictures = path.list_files(dirname .. "attack_level?.png"),
414+ },
415+ defense = {
416+ max_level = 0,
417+ base = 5,
418+ increase_per_level = 5,
419+ pictures = path.list_files(dirname .. "defense_level?.png"),
420+ },
421+ evade = {
422+ max_level = 2,
423+ base = 30,
424+ increase_per_level = 16,
425+ pictures = path.list_files(dirname .. "evade_level?.png"),
426+ },
427
428 -- Random animations for battle
429 attack_success_w = {
430
431=== modified file 'src/ai/defaultai.cc'
432--- src/ai/defaultai.cc 2016-02-27 20:46:11 +0000
433+++ src/ai/defaultai.cc 2016-03-09 16:59:37 +0000
434@@ -5370,37 +5370,37 @@
435 soldiers.at(0)->get_owner()->tribe().name().c_str());
436 }
437
438- float hp = 0;
439- float al = 0;
440- float dl = 0;
441- float el = 0;
442+ float health = 0;
443+ float attack = 0;
444+ float defense = 0;
445+ float evade = 0;
446 float final = 0;
447
448 for (Soldier * soldier : soldiers) {
449 switch (tribe) {
450 case (Tribes::kAtlanteans):
451- hp = 135 + 40 * soldier->get_hp_level();
452- al = 14 + 8 * soldier->get_attack_level();
453- dl = static_cast<float>(94 - 8 * soldier->get_defense_level()) / 100;
454- el = static_cast<float>(70 - 17 * soldier->get_evade_level()) / 100;
455+ health = 135 + 40 * soldier->get_health_level();
456+ attack = 14 + 8 * soldier->get_attack_level();
457+ defense = static_cast<float>(94 - 8 * soldier->get_defense_level()) / 100;
458+ evade = static_cast<float>(70 - 17 * soldier->get_evade_level()) / 100;
459 break;
460 case (Tribes::kBarbarians):
461- hp += 130 + 28 * soldier->get_hp_level();
462- al += 14 + 7 * soldier->get_attack_level();
463- dl += static_cast<float>(97 - 8 * soldier->get_defense_level()) / 100;
464- el += static_cast<float>(75 - 15 * soldier->get_evade_level()) / 100;
465+ health += 130 + 28 * soldier->get_health_level();
466+ attack += 14 + 7 * soldier->get_attack_level();
467+ defense += static_cast<float>(97 - 8 * soldier->get_defense_level()) / 100;
468+ evade += static_cast<float>(75 - 15 * soldier->get_evade_level()) / 100;
469 break;
470 case (Tribes::kEmpire):
471- hp += 130 + 21 * soldier->get_hp_level();
472- al += 14 + 8 * soldier->get_attack_level();
473- dl += static_cast<float>(95 - 8 * soldier->get_defense_level()) / 100;
474- el += static_cast<float>(70 - 16 * soldier->get_evade_level()) / 100;
475+ health += 130 + 21 * soldier->get_health_level();
476+ attack += 14 + 8 * soldier->get_attack_level();
477+ defense += static_cast<float>(95 - 8 * soldier->get_defense_level()) / 100;
478+ evade += static_cast<float>(70 - 16 * soldier->get_evade_level()) / 100;
479 break;
480 default:
481 NEVER_HERE();
482 }
483
484- final += (al * hp) / (dl * el);
485+ final += (attack * health) / (defense * evade);
486 }
487
488 // 2500 is aproximate strength of one unpromoted soldier
489
490=== modified file 'src/logic/findbob.cc'
491--- src/logic/findbob.cc 2016-02-15 23:26:42 +0000
492+++ src/logic/findbob.cc 2016-03-09 16:59:37 +0000
493@@ -36,7 +36,7 @@
494 if
495 (soldier->is_on_battlefield() &&
496 (!player || soldier->owner().is_hostile(*player)) &&
497- soldier->get_current_hitpoints())
498+ soldier->get_current_health())
499 return true;
500
501 return false;
502
503=== modified file 'src/logic/game.cc'
504--- src/logic/game.cc 2016-03-02 16:30:42 +0000
505+++ src/logic/game.cc 2016-03-09 16:59:37 +0000
506@@ -792,11 +792,11 @@
507
508
509 void Game::send_player_change_training_options
510- (TrainingSite & ts, int32_t const atr, int32_t const val)
511+ (TrainingSite & ts, TrainingAttribute attr, int32_t const val)
512 {
513 send_player_command
514 (*new CmdChangeTrainingOptions
515- (get_gametime(), ts.owner().player_number(), ts, atr, val));
516+ (get_gametime(), ts.owner().player_number(), ts, attr, val));
517 }
518
519 void Game::send_player_drop_soldier (Building & b, int32_t const ser)
520@@ -931,7 +931,7 @@
521 for (Bob const * b = fc.field->get_first_bob(); b; b = b->get_next_bob())
522 if (upcast(Soldier const, s, b))
523 miltary_strength[s->owner().player_number() - 1] +=
524- s->get_level(atrTotal) + 1; // So that level 0 also counts.
525+ s->get_level(TrainingAttribute::kTotal) + 1; // So that level 0 also counts.
526 }
527
528 // Number of workers / wares / casualties / kills.
529
530=== modified file 'src/logic/game.h'
531--- src/logic/game.h 2016-02-21 18:02:23 +0000
532+++ src/logic/game.h 2016-03-09 16:59:37 +0000
533@@ -184,7 +184,7 @@
534 (PlayerImmovable &, int32_t type, DescriptionIndex index, int32_t prio);
535 void send_player_set_ware_max_fill
536 (PlayerImmovable &, DescriptionIndex index, uint32_t);
537- void send_player_change_training_options(TrainingSite &, int32_t, int32_t);
538+ void send_player_change_training_options(TrainingSite &, TrainingAttribute, int32_t);
539 void send_player_drop_soldier(Building &, int32_t);
540 void send_player_change_soldier_capacity(Building &, int32_t);
541 void send_player_enemyflagaction
542
543=== modified file 'src/logic/map_objects/map_object.cc'
544--- src/logic/map_objects/map_object.cc 2016-02-07 09:30:20 +0000
545+++ src/logic/map_objects/map_object.cc 2016-03-09 16:59:37 +0000
546@@ -487,7 +487,7 @@
547 /**
548 * Default implementation
549 */
550-int32_t MapObject::get_training_attribute(uint32_t) const
551+int32_t MapObject::get_training_attribute(TrainingAttribute) const
552 {
553 return -1;
554 }
555
556=== modified file 'src/logic/map_objects/map_object.h'
557--- src/logic/map_objects/map_object.h 2016-02-09 16:29:48 +0000
558+++ src/logic/map_objects/map_object.h 2016-03-09 16:59:37 +0000
559@@ -35,6 +35,7 @@
560 #include "graphic/color.h"
561 #include "graphic/image.h"
562 #include "logic/cmd_queue.h"
563+#include "logic/map_objects/tribes/training_attribute.h"
564 #include "logic/widelands.h"
565 #include "scripting/lua_table.h"
566
567@@ -271,7 +272,7 @@
568 * doesn't have this kind of attribute.
569 * The default behaviour returns \c -1 for all attributes.
570 */
571- virtual int32_t get_training_attribute(uint32_t attr) const;
572+ virtual int32_t get_training_attribute(TrainingAttribute attr) const;
573
574 void remove(EditorGameBase &);
575 virtual void destroy(EditorGameBase &);
576
577=== modified file 'src/logic/map_objects/tribes/battle.cc'
578--- src/logic/map_objects/tribes/battle.cc 2016-02-08 17:25:17 +0000
579+++ src/logic/map_objects/tribes/battle.cc 2016-03-09 16:59:37 +0000
580@@ -71,7 +71,7 @@
581 }
582
583 // Ensures only live soldiers eganges in a battle
584- assert(First.get_current_hitpoints() && Second.get_current_hitpoints());
585+ assert(First.get_current_health() && Second.get_current_health());
586
587 init(game);
588 }
589@@ -184,7 +184,7 @@
590 damage_ = 0;
591 }
592
593- if (soldier.get_current_hitpoints() < 1) {
594+ if (soldier.get_current_health() < 1) {
595 molog("[battle] soldier %u lost the battle\n", soldier.serial());
596 soldier . owner().count_casualty();
597 opponent(soldier)->owner().count_kill ();
598
599=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
600--- src/logic/map_objects/tribes/militarysite.cc 2016-03-02 17:54:32 +0000
601+++ src/logic/map_objects/tribes/militarysite.cc 2016-03-09 16:59:37 +0000
602@@ -294,7 +294,7 @@
603 int worst_soldier_level = INT_MIN;
604 Soldier * worst_soldier = nullptr;
605 for (Soldier* sld : present) {
606- int this_soldier_level = multiplier * static_cast<int> (sld->get_level(atrTotal));
607+ int this_soldier_level = multiplier * static_cast<int> (sld->get_level(TrainingAttribute::kTotal));
608 if (this_soldier_level > worst_soldier_level)
609 {
610 worst_soldier_level = this_soldier_level;
611@@ -332,8 +332,8 @@
612 // If the arriving guy is worse than worst present, I wont't release.
613 if (nullptr != newguy && nullptr != kickoutCandidate)
614 {
615- int32_t old_level = kickoutCandidate->get_level(atrTotal);
616- int32_t new_level = newguy->get_level(atrTotal);
617+ int32_t old_level = kickoutCandidate->get_level(TrainingAttribute::kTotal);
618+ int32_t new_level = newguy->get_level(TrainingAttribute::kTotal);
619 if (kPrefersHeroes == soldier_preference_ && old_level >= new_level)
620 {
621 return false;
622@@ -604,12 +604,12 @@
623 // The healing algorithm is:
624 // * heal soldier with highest total level
625 // * heal healthiest if multiple of same total level exist
626- if (s->get_current_hitpoints() < s->get_max_hitpoints()) {
627+ if (s->get_current_health() < s->get_max_health()) {
628 if (0 == soldier_to_heal || s->get_total_level() > max_total_level ||
629 (s->get_total_level() == max_total_level &&
630- s->get_current_hitpoints() / s->get_max_hitpoints() > max_health)) {
631+ s->get_current_health() / s->get_max_health() > max_health)) {
632 max_total_level = s->get_total_level();
633- max_health = s->get_current_hitpoints() / s->get_max_hitpoints();
634+ max_health = s->get_current_health() / s->get_max_health();
635 soldier_to_heal = s;
636 }
637 }
638@@ -829,12 +829,12 @@
639 Soldier * defender = nullptr;
640
641 if (!present.empty()) {
642- // Find soldier with greatest hitpoints
643+ // Find soldier with greatest health
644 uint32_t current_max = 0;
645 for (Soldier * temp_soldier : present) {
646- if (temp_soldier->get_current_hitpoints() > current_max) {
647+ if (temp_soldier->get_current_health() > current_max) {
648 defender = temp_soldier;
649- current_max = defender->get_current_hitpoints();
650+ current_max = defender->get_current_health();
651 }
652 }
653 } else {
654@@ -1079,7 +1079,7 @@
655 // There could be no soldier in the militarysite right now. No reason to freak out.
656 return false;
657 }
658- int32_t wg_level = worst_guy->get_level(atrTotal);
659+ int32_t wg_level = worst_guy->get_level(TrainingAttribute::kTotal);
660
661 // Micro-optimization: I assume that the majority of military sites have only level-zero
662 // soldiers and prefer rookies. Handle them separately.
663@@ -1105,7 +1105,7 @@
664 {
665 upgrade_soldier_request_.reset();
666 }
667- soldier_upgrade_requirements_ = RequireAttribute(atrTotal, reqmin, reqmax);
668+ soldier_upgrade_requirements_ = RequireAttribute(TrainingAttribute::kTotal, reqmin, reqmax);
669
670 return true;
671 }
672
673=== modified file 'src/logic/map_objects/tribes/production_program.cc'
674--- src/logic/map_objects/tribes/production_program.cc 2016-03-01 08:22:57 +0000
675+++ src/logic/map_objects/tribes/production_program.cc 2016-03-09 16:59:37 +0000
676@@ -1354,18 +1354,18 @@
677 throw GameDataError
678 ("expected %s but found \"%s\"", "soldier type", parameters);
679 try {
680- if (match_force_skip(parameters, "hp"))
681- attribute = atrHP;
682+ if (match_force_skip(parameters, "health"))
683+ attribute = TrainingAttribute::kHealth;
684 else if (match_force_skip(parameters, "attack"))
685- attribute = atrAttack;
686+ attribute = TrainingAttribute::kAttack;
687 else if (match_force_skip(parameters, "defense"))
688- attribute = atrDefense;
689+ attribute = TrainingAttribute::kDefense;
690 else if (match_force_skip(parameters, "evade"))
691- attribute = atrEvade;
692+ attribute = TrainingAttribute::kEvade;
693 else
694 throw GameDataError
695 ("expected %s but found \"%s\"",
696- "{\"hp\"|\"attack\"|\"defense\"|\"evade\"}", parameters);
697+ "{\"health\"|\"attack\"|\"defense\"|\"evade\"}", parameters);
698
699 char * endp;
700 unsigned long long int const value = strtoull(parameters, &endp, 0);
701@@ -1395,16 +1395,16 @@
702 ps.set_production_result(_("No soldier found for this training level!"));
703 return ps.program_end(game, Skipped);
704 }
705- if (attribute == atrHP) {
706- if ((*it)->get_hp_level() == level)
707+ if (attribute == TrainingAttribute::kHealth) {
708+ if ((*it)->get_health_level() == level)
709 break;
710- } else if (attribute == atrAttack) {
711+ } else if (attribute == TrainingAttribute::kAttack) {
712 if ((*it)->get_attack_level() == level)
713 break;
714- } else if (attribute == atrDefense) {
715+ } else if (attribute == TrainingAttribute::kDefense) {
716 if ((*it)->get_defense_level() == level)
717 break;
718- } else if (attribute == atrEvade) {
719+ } else if (attribute == TrainingAttribute::kEvade) {
720 if ((*it)->get_evade_level() == level)
721 break;
722 }
723@@ -1426,18 +1426,18 @@
724 throw GameDataError
725 ("expected %s but found \"%s\"", "soldier type", parameters);
726 try {
727- if (match_force_skip(parameters, "hp"))
728- attribute = atrHP;
729+ if (match_force_skip(parameters, "health"))
730+ attribute = TrainingAttribute::kHealth;
731 else if (match_force_skip(parameters, "attack"))
732- attribute = atrAttack;
733+ attribute = TrainingAttribute::kAttack;
734 else if (match_force_skip(parameters, "defense"))
735- attribute = atrDefense;
736+ attribute = TrainingAttribute::kDefense;
737 else if (match_force_skip(parameters, "evade"))
738- attribute = atrEvade;
739+ attribute = TrainingAttribute::kEvade;
740 else
741 throw GameDataError
742 ("expected %s but found \"%s\"",
743- "{\"hp\"|\"attack\"|\"defense\"|\"evade\"}", parameters);
744+ "{\"health\"|\"attack\"|\"defense\"|\"evade\"}", parameters);
745
746 {
747 char * endp;
748@@ -1480,31 +1480,32 @@
749 ps.set_production_result(_("No soldier found for this training level!"));
750 return ps.program_end(game, Skipped);
751 }
752- if (attribute == atrHP) {
753- if ((*it)->get_hp_level () == level)
754+ if (attribute == TrainingAttribute::kHealth) {
755+ if ((*it)->get_health_level () == level)
756 break;
757- } else if (attribute == atrAttack) {
758+ } else if (attribute == TrainingAttribute::kAttack) {
759 if ((*it)->get_attack_level () == level)
760 break;
761- } else if (attribute == atrDefense) {
762+ } else if (attribute == TrainingAttribute::kDefense) {
763 if ((*it)->get_defense_level() == level)
764 break;
765- } else if (attribute == atrEvade)
766+ } else if (attribute == TrainingAttribute::kEvade) {
767 if ((*it)->get_evade_level () == level)
768 break;
769+ }
770 }
771 ps.molog(" okay\n"); // okay, do nothing
772
773 try {
774- if (attribute == atrHP)
775- (*it)->set_hp_level (target_level);
776- else if (attribute == atrAttack)
777+ if (attribute == TrainingAttribute::kHealth)
778+ (*it)->set_health_level (target_level);
779+ else if (attribute == TrainingAttribute::kAttack)
780 (*it)->set_attack_level (target_level);
781
782- else if (attribute == atrDefense)
783+ else if (attribute == TrainingAttribute::kDefense)
784 (*it)->set_defense_level (target_level);
785
786- else if (attribute == atrEvade)
787+ else if (attribute == TrainingAttribute::kEvade)
788 (*it)->set_evade_level (target_level);
789
790 } catch (...) {
791
792=== modified file 'src/logic/map_objects/tribes/requirements.cc'
793--- src/logic/map_objects/tribes/requirements.cc 2016-02-14 14:09:29 +0000
794+++ src/logic/map_objects/tribes/requirements.cc 2016-03-09 16:59:37 +0000
795@@ -32,7 +32,7 @@
796 return !m || m->check(obj);
797 }
798
799-constexpr uint16_t kCurrentPacketVersion = 3;
800+constexpr uint16_t kCurrentPacketVersion = 4;
801
802 /**
803 * Read this requirement from a file
804@@ -201,7 +201,7 @@
805
806 bool RequireAttribute::check(const MapObject & obj) const
807 {
808- if (atrTotal != at)
809+ if (TrainingAttribute::kTotal != at)
810 {
811 int32_t const value = obj.get_training_attribute(at);
812
813@@ -210,10 +210,10 @@
814 else
815 {
816 int32_t value = 0;
817- value += obj.get_training_attribute(atrHP);
818- value += obj.get_training_attribute(atrAttack);
819- value += obj.get_training_attribute(atrDefense);
820- value += obj.get_training_attribute(atrEvade);
821+ value += obj.get_training_attribute(TrainingAttribute::kHealth);
822+ value += obj.get_training_attribute(TrainingAttribute::kAttack);
823+ value += obj.get_training_attribute(TrainingAttribute::kDefense);
824+ value += obj.get_training_attribute(TrainingAttribute::kEvade);
825 return value >= min && value <= max;
826 }
827 }
828@@ -221,7 +221,7 @@
829 void RequireAttribute::write
830 (FileWrite & fw, EditorGameBase &, MapObjectSaver &) const
831 {
832- fw.unsigned_32(at);
833+ fw.unsigned_8(static_cast<uint8_t>(at));
834 fw.signed_32(min);
835 fw.signed_32(max);
836 }
837@@ -229,16 +229,30 @@
838 static Requirements read_attribute
839 (FileRead & fr, EditorGameBase &, MapObjectLoader &)
840 {
841- TrainingAttribute const at = static_cast<TrainingAttribute>(fr.unsigned_32());
842- if
843- (at != atrHP && at != atrAttack && at != atrDefense && at != atrEvade
844- &&
845- at != atrTotal)
846+ // Get the training attribute and check if it is a valid enum member
847+ // We use a temp value, because the static_cast to the enum might be undefined.
848+ uint8_t temp_at = fr.unsigned_8();
849+ switch (temp_at) {
850+ case static_cast<uint8_t>(TrainingAttribute::kHealth):
851+ case static_cast<uint8_t>(TrainingAttribute::kAttack):
852+ case static_cast<uint8_t>(TrainingAttribute::kDefense):
853+ case static_cast<uint8_t>(TrainingAttribute::kEvade):
854+ case static_cast<uint8_t>(TrainingAttribute::kTotal):
855+ break;
856+ default:
857 throw GameDataError
858 (
859- "expected atrHP (%u), atrAttack (%u), atrDefense (%u), atrEvade "
860- "(%u) or atrTotal (%u) but found unknown attribute value (%u)",
861- atrHP, atrAttack, atrDefense, atrEvade, atrTotal, at);
862+ "expected kHealth (%u), kAttack (%u), kDefense (%u), kEvade "
863+ "(%u) or kTotal (%u) but found unknown attribute value (%u)",
864+ TrainingAttribute::kHealth,
865+ TrainingAttribute::kAttack,
866+ TrainingAttribute::kDefense,
867+ TrainingAttribute::kEvade,
868+ TrainingAttribute::kTotal,
869+ temp_at);
870+ }
871+ TrainingAttribute const at = static_cast<TrainingAttribute>(temp_at);
872+
873 int32_t const min = fr.signed_32();
874 int32_t const max = fr.signed_32();
875
876
877=== modified file 'src/logic/map_objects/tribes/requirements.h'
878--- src/logic/map_objects/tribes/requirements.h 2016-02-14 14:09:29 +0000
879+++ src/logic/map_objects/tribes/requirements.h 2016-03-09 16:59:37 +0000
880@@ -176,7 +176,7 @@
881 (TrainingAttribute const init_at, int32_t const init_min, int32_t const init_max)
882 : at(init_at), min(init_min), max(init_max) {}
883
884- RequireAttribute() : at(atrTotal), min(SHRT_MIN), max(SHRT_MAX) {}
885+ RequireAttribute() : at(TrainingAttribute::kTotal), min(SHRT_MIN), max(SHRT_MAX) {}
886 bool check(const MapObject &) const;
887 void write
888 (FileWrite &, EditorGameBase & egbase, MapObjectSaver &) const;
889
890=== modified file 'src/logic/map_objects/tribes/soldier.cc'
891--- src/logic/map_objects/tribes/soldier.cc 2016-03-02 16:30:42 +0000
892+++ src/logic/map_objects/tribes/soldier.cc 2016-03-09 16:59:37 +0000
893@@ -64,58 +64,15 @@
894 SoldierDescr::SoldierDescr(const std::string& init_descname,
895 const LuaTable& table,
896 const EditorGameBase& egbase) :
897- WorkerDescr(init_descname, MapObjectType::SOLDIER, table, egbase)
898+ WorkerDescr(init_descname, MapObjectType::SOLDIER, table, egbase),
899+ health_(table.get_table("health")),
900+ attack_(table.get_table("attack")),
901+ defense_(table.get_table("defense")),
902+ evade_(table.get_table("evade"))
903 {
904 add_attribute(MapObject::Attribute::SOLDIER);
905
906- base_hp_ = table.get_int("hp");
907-
908- // Parse attack
909- std::unique_ptr<LuaTable> items_table = table.get_table("attack");
910- min_attack_ = items_table->get_int("minimum");
911- max_attack_ = items_table->get_int("maximum");
912- if (min_attack_ > max_attack_) {
913- throw GameDataError("Minimum attack %d is greater than maximum attack %d.", min_attack_, max_attack_);
914- }
915-
916- // Parse defend
917- defense_ = table.get_int("defense");
918-
919- // Parse evade
920- evade_ = table.get_int("evade");
921-
922- // Parse increases per level
923- hp_incr_ = table.get_int("hp_incr_per_level");
924- attack_incr_ = table.get_int("attack_incr_per_level");
925- defense_incr_ = table.get_int("defense_incr_per_level");
926- evade_incr_ = table.get_int("evade_incr_per_level");
927-
928- // Parse max levels
929- max_hp_level_ = table.get_int("max_hp_level");
930- max_attack_level_ = table.get_int("max_attack_level");
931- max_defense_level_ = table.get_int("max_defense_level");
932- max_evade_level_ = table.get_int("max_evade_level");
933-
934- // Load the filenames
935- hp_pics_fn_ .resize(max_hp_level_ + 1);
936- attack_pics_fn_ .resize(max_attack_level_ + 1);
937- defense_pics_fn_.resize(max_defense_level_ + 1);
938- evade_pics_fn_ .resize(max_evade_level_ + 1);
939-
940- for (uint32_t i = 0; i <= max_hp_level_; ++i) {
941- hp_pics_fn_[i] = table.get_string((boost::format("hp_level_%u_pic") % i).str());
942- }
943- for (uint32_t i = 0; i <= max_attack_level_; ++i) {
944- attack_pics_fn_[i] = table.get_string((boost::format("attack_level_%u_pic") % i).str());
945- }
946- for (uint32_t i = 0; i <= max_defense_level_; ++i) {
947- defense_pics_fn_[i] = table.get_string((boost::format("defense_level_%u_pic") % i).str());
948- }
949- for (uint32_t i = 0; i <= max_evade_level_; ++i) {
950- evade_pics_fn_[i] = table.get_string((boost::format("evade_level_%u_pic") % i).str());
951- }
952-
953- // Battle animations
954+ // Battle animations
955 // attack_success_*-> soldier is attacking and hit his opponent
956 add_battle_animation(table.get_table("attack_success_w"), &attack_success_w_name_);
957 add_battle_animation(table.get_table("attack_success_e"), &attack_success_e_name_);
958@@ -135,23 +92,32 @@
959 // die_* -> soldier is dying
960 add_battle_animation(table.get_table("die_w"), &die_w_name_);
961 add_battle_animation(table.get_table("die_e"), &die_e_name_);
962+}
963+
964+SoldierDescr::BattleAttribute::BattleAttribute(std::unique_ptr<LuaTable> table) {
965+ base = table->get_int("base");
966+
967+ if (table->has_key("maximum")) {
968+ maximum = table->get_int("maximum");
969+ if (base > maximum) {
970+ throw GameDataError("Base %d is greater than maximum %d for a soldier's battle attribute.",
971+ base, maximum);
972+ }
973+ } else {
974+ maximum = base;
975+ }
976+ increase = table->get_int("increase_per_level");
977+ max_level = table->get_int("max_level");
978
979 // Load Graphics
980- hp_pics_ .resize(max_hp_level_ + 1);
981- attack_pics_ .resize(max_attack_level_ + 1);
982- defense_pics_.resize(max_defense_level_ + 1);
983- evade_pics_ .resize(max_evade_level_ + 1);
984- for (uint32_t i = 0; i <= max_hp_level_; ++i)
985- hp_pics_[i] = g_gr->images().get(hp_pics_fn_[i]);
986- for (uint32_t i = 0; i <= max_attack_level_; ++i)
987- attack_pics_[i] =
988- g_gr->images().get(attack_pics_fn_[i]);
989- for (uint32_t i = 0; i <= max_defense_level_; ++i)
990- defense_pics_[i] =
991- g_gr->images().get(defense_pics_fn_[i]);
992- for (uint32_t i = 0; i <= max_evade_level_; ++i)
993- evade_pics_[i] =
994- g_gr->images().get(evade_pics_fn_[i]);
995+ std::vector<std::string> image_filenames = table->get_table("pictures")->array_entries<std::string>();
996+ if (image_filenames.size() != max_level + 1) {
997+ throw GameDataError("Soldier needs to have %d pictures for battle attribute, but found %lu",
998+ max_level + 1, image_filenames.size());
999+ }
1000+ for (const std::string& image_filename : image_filenames) {
1001+ images.push_back(g_gr->images().get(image_filename));
1002+ }
1003 }
1004
1005 /**
1006@@ -253,12 +219,12 @@
1007 Soldier::Soldier(const SoldierDescr & soldier_descr) : Worker(soldier_descr)
1008 {
1009 battle_ = nullptr;
1010- hp_level_ = 0;
1011+ health_level_ = 0;
1012 attack_level_ = 0;
1013 defense_level_ = 0;
1014 evade_level_ = 0;
1015
1016- hp_current_ = get_max_hitpoints();
1017+ current_health_ = get_max_health();
1018
1019 combat_walking_ = CD_NONE;
1020 combat_walkstart_ = 0;
1021@@ -268,12 +234,12 @@
1022
1023 void Soldier::init(EditorGameBase & egbase)
1024 {
1025- hp_level_ = 0;
1026+ health_level_ = 0;
1027 attack_level_ = 0;
1028 defense_level_ = 0;
1029 evade_level_ = 0;
1030
1031- hp_current_ = get_max_hitpoints();
1032+ current_health_ = get_max_health();
1033
1034 combat_walking_ = CD_NONE;
1035 combat_walkstart_ = 0;
1036@@ -296,26 +262,26 @@
1037 * Set this soldiers level. Automatically sets the new values
1038 */
1039 void Soldier::set_level
1040- (uint32_t const hp,
1041+ (uint32_t const health,
1042 uint32_t const attack,
1043 uint32_t const defense,
1044 uint32_t const evade)
1045 {
1046- set_hp_level(hp);
1047+ set_health_level(health);
1048 set_attack_level(attack);
1049 set_defense_level(defense);
1050 set_evade_level(evade);
1051 }
1052-void Soldier::set_hp_level(const uint32_t hp) {
1053- assert(hp_level_ <= hp);
1054- assert (hp <= descr().get_max_hp_level());
1055-
1056- uint32_t oldmax = get_max_hitpoints();
1057-
1058- hp_level_ = hp;
1059-
1060- uint32_t newmax = get_max_hitpoints();
1061- hp_current_ = hp_current_ * newmax / oldmax;
1062+void Soldier::set_health_level(const uint32_t health) {
1063+ assert(health_level_ <= health);
1064+ assert(health <= descr().get_max_health_level());
1065+
1066+ uint32_t oldmax = get_max_health();
1067+
1068+ health_level_ = health;
1069+
1070+ uint32_t newmax = get_max_health();
1071+ current_health_ = current_health_ * newmax / oldmax;
1072 }
1073 void Soldier::set_attack_level(const uint32_t attack) {
1074 assert(attack_level_ <= attack);
1075@@ -338,34 +304,34 @@
1076
1077 uint32_t Soldier::get_level(TrainingAttribute const at) const {
1078 switch (at) {
1079- case atrHP: return hp_level_;
1080- case atrAttack: return attack_level_;
1081- case atrDefense: return defense_level_;
1082- case atrEvade: return evade_level_;
1083- case atrTotal:
1084- return hp_level_ + attack_level_ + defense_level_ + evade_level_;
1085+ case TrainingAttribute::kHealth: return health_level_;
1086+ case TrainingAttribute::kAttack: return attack_level_;
1087+ case TrainingAttribute::kDefense: return defense_level_;
1088+ case TrainingAttribute::kEvade: return evade_level_;
1089+ case TrainingAttribute::kTotal:
1090+ return health_level_ + attack_level_ + defense_level_ + evade_level_;
1091 }
1092 NEVER_HERE();
1093 }
1094
1095
1096-int32_t Soldier::get_training_attribute(uint32_t const attr) const
1097+int32_t Soldier::get_training_attribute(TrainingAttribute const attr) const
1098 {
1099 switch (attr) {
1100- case atrHP: return hp_level_;
1101- case atrAttack: return attack_level_;
1102- case atrDefense: return defense_level_;
1103- case atrEvade: return evade_level_;
1104- case atrTotal:
1105- return hp_level_ + attack_level_ + defense_level_ + evade_level_;
1106+ case TrainingAttribute::kHealth: return health_level_;
1107+ case TrainingAttribute::kAttack: return attack_level_;
1108+ case TrainingAttribute::kDefense: return defense_level_;
1109+ case TrainingAttribute::kEvade: return evade_level_;
1110+ case TrainingAttribute::kTotal:
1111+ return health_level_ + attack_level_ + defense_level_ + evade_level_;
1112 default:
1113 return Worker::get_training_attribute(attr);
1114 }
1115 }
1116
1117-uint32_t Soldier::get_max_hitpoints() const
1118+uint32_t Soldier::get_max_health() const
1119 {
1120- return descr().get_base_hp() + hp_level_ * descr().get_hp_incr_per_level();
1121+ return descr().get_base_health() + health_level_ * descr().get_health_incr_per_level();
1122 }
1123
1124 uint32_t Soldier::get_min_attack() const
1125@@ -397,29 +363,29 @@
1126 }
1127
1128 // Unsignedness ensures that we can only heal, not hurt through this method.
1129-void Soldier::heal (const uint32_t hp) {
1130+void Soldier::heal (const uint32_t health) {
1131 molog
1132- ("[soldier] healing (%d+)%d/%d\n", hp, hp_current_, get_max_hitpoints());
1133- assert(hp);
1134- assert(hp_current_ < get_max_hitpoints());
1135- hp_current_ += std::min(hp, get_max_hitpoints() - hp_current_);
1136- assert(hp_current_ <= get_max_hitpoints());
1137+ ("[soldier] healing (%d+)%d/%d\n", health, current_health_, get_max_health());
1138+ assert(health);
1139+ assert(current_health_ < get_max_health());
1140+ current_health_ += std::min(health, get_max_health() - current_health_);
1141+ assert(current_health_ <= get_max_health());
1142 }
1143
1144 /**
1145- * This only subs the specified number of hitpoints, don't do anything more.
1146+ * This only subs the specified number of health points, don't do anything more.
1147 */
1148 void Soldier::damage (const uint32_t value)
1149 {
1150- assert (hp_current_ > 0);
1151+ assert (current_health_ > 0);
1152
1153 molog
1154 ("[soldier] damage %d(-%d)/%d\n",
1155- hp_current_, value, get_max_hitpoints());
1156- if (hp_current_ < value)
1157- hp_current_ = 0;
1158+ current_health_, value, get_max_health());
1159+ if (current_health_ < value)
1160+ current_health_ = 0;
1161 else
1162- hp_current_ -= value;
1163+ current_health_ -= value;
1164 }
1165
1166 /// Calculates the actual position to draw on from the base node position.
1167@@ -486,7 +452,7 @@
1168 }
1169
1170 /*
1171- * Draw this soldier. This basically draws him as a worker, but add hitpoints
1172+ * Draw this soldier. This basically draws him as a worker, but add health points
1173 */
1174 void Soldier::draw
1175 (const EditorGameBase & game, RenderTarget & dst, const Point& pos) const
1176@@ -501,7 +467,7 @@
1177 }
1178
1179 /**
1180- * Draw the info icon (level indicators + HP bar) for this soldier.
1181+ * Draw the info icon (level indicators + health bar) for this soldier.
1182 *
1183 * \param anchor_below if \c true, the icon is drawn horizontally centered above
1184 * \p pt. Otherwise, the icon is drawn below and right of \p pt.
1185@@ -511,15 +477,15 @@
1186 {
1187 // Gather information to determine coordinates
1188 uint32_t w;
1189- w = kSoldierHpBarWidth;
1190+ w = kSoldierHealthBarWidth;
1191
1192- const Image* hppic = get_hp_level_pic();
1193+ const Image* healthpic = get_health_level_pic();
1194 const Image* attackpic = get_attack_level_pic();
1195 const Image* defensepic = get_defense_level_pic();
1196 const Image* evadepic = get_evade_level_pic();
1197
1198- uint16_t hpw = hppic->width();
1199- uint16_t hph = hppic->height();
1200+ uint16_t hpw = healthpic->width();
1201+ uint16_t hph = healthpic->height();
1202 uint16_t atw = attackpic->width();
1203 uint16_t ath = attackpic->height();
1204 uint16_t dew = defensepic->width();
1205@@ -539,10 +505,10 @@
1206
1207 // Draw energy bar
1208 Rect energy_outer(Point(pt.x - w, pt.y), w * 2, 5);
1209- dst.draw_rect(energy_outer, HP_FRAMECOLOR);
1210+ dst.draw_rect(energy_outer, RGBColor(255, 255, 255));
1211
1212- assert(get_max_hitpoints());
1213- uint32_t health_width = 2 * (w - 1) * hp_current_ / get_max_hitpoints();
1214+ assert(get_max_health());
1215+ uint32_t health_width = 2 * (w - 1) * current_health_ / get_max_health();
1216 Rect energy_inner(Point(pt.x - w + 1, pt.y + 1), health_width, 3);
1217 Rect energy_complement
1218 (energy_inner.origin() + Point(health_width, 0), 2 * (w - 1) - health_width, 3);
1219@@ -561,13 +527,13 @@
1220 {
1221 dst.blit(pt + Point(-atw, -(hph + ath)), attackpic);
1222 dst.blit(pt + Point(0, -(evh + deh)), defensepic);
1223- dst.blit(pt + Point(-hpw, -hph), hppic);
1224+ dst.blit(pt + Point(-hpw, -hph), healthpic);
1225 dst.blit(pt + Point(0, -evh), evadepic);
1226 }
1227 }
1228
1229 /**
1230- * Compute the size of the info icon (level indicators + HP bar) for soldiers of
1231+ * Compute the size of the info icon (level indicators + health bar) for soldiers of
1232 * the given tribe.
1233 */
1234 void Soldier::calc_info_icon_size
1235@@ -575,12 +541,12 @@
1236 {
1237 const SoldierDescr * soldierdesc = static_cast<const SoldierDescr *>
1238 (tribe.get_worker_descr(tribe.soldier()));
1239- const Image* hppic = soldierdesc->get_hp_level_pic(0);
1240+ const Image* healthpic = soldierdesc->get_health_level_pic(0);
1241 const Image* attackpic = soldierdesc->get_attack_level_pic(0);
1242 const Image* defensepic = soldierdesc->get_defense_level_pic(0);
1243 const Image* evadepic = soldierdesc->get_evade_level_pic(0);
1244- uint16_t hpw = hppic->width();
1245- uint16_t hph = hppic->height();
1246+ uint16_t hpw = healthpic->width();
1247+ uint16_t hph = healthpic->height();
1248 uint16_t atw = attackpic->width();
1249 uint16_t ath = attackpic->height();
1250 uint16_t dew = defensepic->width();
1251@@ -589,7 +555,7 @@
1252 uint16_t evh = evadepic->height();
1253
1254 uint16_t animw;
1255- animw = kSoldierHpBarWidth;
1256+ animw = kSoldierHealthBarWidth;
1257
1258 w = std::max(std::max(atw + dew, hpw + evw), 2 * animw);
1259 h = 5 + std::max(hph + ath, evh + deh);
1260@@ -657,7 +623,7 @@
1261 */
1262 bool Soldier::can_be_challenged()
1263 {
1264- if (hp_current_ < 1) { //< Soldier is dead!
1265+ if (current_health_ < 1) { //< Soldier is dead!
1266 return false;
1267 }
1268 if (!is_on_battlefield()) {
1269@@ -686,7 +652,7 @@
1270 * Set a fallback task.
1271 */
1272 void Soldier::init_auto_task(Game & game) {
1273- if (get_current_hitpoints() < 1) {
1274+ if (get_current_health() < 1) {
1275 molog("[soldier] init_auto_task: die\n");
1276 return start_task_die(game);
1277 }
1278@@ -730,11 +696,11 @@
1279 state.ivar3 = 0; // Counts how often the soldier is blocked in a row
1280
1281 state.ivar1 |= CF_RETREAT_WHEN_INJURED;
1282- state.ui32var3 = kRetreatWhenHealthDropsBelowThisPercentage * get_max_hitpoints() / 100;
1283+ state.ui32var3 = kRetreatWhenHealthDropsBelowThisPercentage * get_max_health() / 100;
1284
1285 // Injured soldiers are not allowed to attack
1286- if (state.ui32var3 > get_current_hitpoints()) {
1287- state.ui32var3 = get_current_hitpoints();
1288+ if (state.ui32var3 > get_current_health()) {
1289+ state.ui32var3 = get_current_health();
1290 }
1291 }
1292
1293@@ -918,11 +884,11 @@
1294 if
1295 (!enemy ||
1296 ((state.ivar1 & CF_RETREAT_WHEN_INJURED) &&
1297- state.ui32var3 > get_current_hitpoints() &&
1298+ state.ui32var3 > get_current_health() &&
1299 defenders > 0))
1300 {
1301 // Injured soldiers will try to return to safe site at home.
1302- if (state.ui32var3 > get_current_hitpoints() && defenders) {
1303+ if (state.ui32var3 > get_current_health() && defenders) {
1304 state.coords = Coords::null();
1305 state.objvar1 = nullptr;
1306 }
1307@@ -1006,7 +972,7 @@
1308 {
1309 if (upcast(Soldier, soldier, bob)) {
1310 return
1311- soldier->get_current_hitpoints() &&
1312+ soldier->get_current_health() &&
1313 soldier->is_attacking_player(game, player) &&
1314 soldier->owner().is_hostile(player);
1315 }
1316@@ -1027,7 +993,7 @@
1317 * Variables used:
1318 * \li ivar1 used to store \c CombatFlags
1319 * \li ivar2 when CF_DEFEND_STAYHOME, 1 if it has reached the flag
1320-// when CF_RETREAT_WHEN_INJURED, the lesser HP before fleeing
1321+// when CF_RETREAT_WHEN_INJURED, the lesser health before fleeing
1322 */
1323 Bob::Task const Soldier::taskDefense = {
1324 "defense",
1325@@ -1053,11 +1019,11 @@
1326 } else {
1327 /* Flag defenders are not allowed to flee, to avoid abuses */
1328 state.ivar1 |= CF_RETREAT_WHEN_INJURED;
1329- state.ui32var3 = get_max_hitpoints() * kRetreatWhenHealthDropsBelowThisPercentage / 100;
1330+ state.ui32var3 = get_max_health() * kRetreatWhenHealthDropsBelowThisPercentage / 100;
1331
1332 // Soldier must defend even if he starts injured
1333- if (state.ui32var3 < get_current_hitpoints())
1334- state.ui32var3 = get_current_hitpoints();
1335+ if (state.ui32var3 < get_current_health())
1336+ state.ui32var3 = get_current_health();
1337 }
1338 }
1339
1340@@ -1163,10 +1129,10 @@
1341 if
1342 (soldiers.empty() ||
1343 ((state.ivar1 & CF_RETREAT_WHEN_INJURED) &&
1344- get_current_hitpoints() < state.ui32var3))
1345+ get_current_health() < state.ui32var3))
1346 {
1347
1348- if (get_current_hitpoints() < state.ui32var3)
1349+ if (get_current_health() < state.ui32var3)
1350 molog("[defense] I am heavily injured!\n");
1351 else
1352 molog("[defense] no enemy soldiers found, ending task\n");
1353@@ -1615,7 +1581,7 @@
1354 if (upcast(Soldier, soldier, bob))
1355 return
1356 soldier->is_on_battlefield() &&
1357- soldier->get_current_hitpoints();
1358+ soldier->get_current_health();
1359 return false;
1360 }
1361 };
1362@@ -1636,7 +1602,7 @@
1363 if
1364 (!attackdefense ||
1365 ((attackdefense->ivar1 & CF_RETREAT_WHEN_INJURED) &&
1366- attackdefense->ui32var3 > get_current_hitpoints()))
1367+ attackdefense->ui32var3 > get_current_health()))
1368 {
1369 // Retreating or non-combatant soldiers act like normal bobs
1370 return Bob::check_node_blocked(game, field, commit);
1371@@ -1661,7 +1627,7 @@
1372 bob; bob = bob->get_next_on_field())
1373 {
1374 if (upcast(Soldier, soldier, bob)) {
1375- if (!soldier->is_on_battlefield() || !soldier->get_current_hitpoints())
1376+ if (!soldier->is_on_battlefield() || !soldier->get_current_health())
1377 continue;
1378
1379 if (!foundsoldier) {
1380@@ -1750,10 +1716,10 @@
1381 molog("[Soldier]\n");
1382 molog
1383 ("Levels: %d/%d/%d/%d\n",
1384- hp_level_, attack_level_, defense_level_, evade_level_);
1385- molog ("HitPoints: %d/%d\n", hp_current_, get_max_hitpoints());
1386- molog ("Attack : %d-%d\n", get_min_attack(), get_max_attack());
1387- molog ("Defense : %d%%\n", get_defense());
1388+ health_level_, attack_level_, defense_level_, evade_level_);
1389+ molog ("Health: %d/%d\n", current_health_, get_max_health());
1390+ molog ("Attack: %d-%d\n", get_min_attack(), get_max_attack());
1391+ molog ("Defense: %d%%\n", get_defense());
1392 molog ("Evade: %d%%\n", get_evade());
1393 molog ("CombatWalkingDir: %i\n", combat_walking_);
1394 molog ("CombatWalkingStart: %i\n", combat_walkstart_);
1395@@ -1789,10 +1755,10 @@
1396 if (packet_version == kCurrentPacketVersion) {
1397
1398 Soldier & soldier = get<Soldier>();
1399- soldier.hp_current_ = fr.unsigned_32();
1400+ soldier.current_health_ = fr.unsigned_32();
1401
1402- soldier.hp_level_ =
1403- std::min(fr.unsigned_32(), soldier.descr().get_max_hp_level());
1404+ soldier.health_level_ =
1405+ std::min(fr.unsigned_32(), soldier.descr().get_max_health_level());
1406 soldier.attack_level_ =
1407 std::min(fr.unsigned_32(), soldier.descr().get_max_attack_level());
1408 soldier.defense_level_ =
1409@@ -1800,8 +1766,8 @@
1410 soldier.evade_level_ =
1411 std::min(fr.unsigned_32(), soldier.descr().get_max_evade_level());
1412
1413- if (soldier.hp_current_ > soldier.get_max_hitpoints())
1414- soldier.hp_current_ = soldier.get_max_hitpoints();
1415+ if (soldier.current_health_ > soldier.get_max_health())
1416+ soldier.current_health_ = soldier.get_max_health();
1417
1418 soldier.combat_walking_ = static_cast<CombatWalkingDir>(fr.unsigned_8());
1419 if (soldier.combat_walking_ != CD_NONE) {
1420@@ -1849,8 +1815,8 @@
1421 Worker::do_save(egbase, mos, fw);
1422
1423 fw.unsigned_8(kCurrentPacketVersion);
1424- fw.unsigned_32(hp_current_);
1425- fw.unsigned_32(hp_level_);
1426+ fw.unsigned_32(current_health_);
1427+ fw.unsigned_32(health_level_);
1428 fw.unsigned_32(attack_level_);
1429 fw.unsigned_32(defense_level_);
1430 fw.unsigned_32(evade_level_);
1431
1432=== modified file 'src/logic/map_objects/tribes/soldier.h'
1433--- src/logic/map_objects/tribes/soldier.h 2016-02-15 23:26:42 +0000
1434+++ src/logic/map_objects/tribes/soldier.h 2016-03-09 16:59:37 +0000
1435@@ -37,8 +37,6 @@
1436 class EditorGameBase;
1437 class Battle;
1438
1439-#define HP_FRAMECOLOR RGBColor(255, 255, 255)
1440-
1441 class SoldierDescr : public WorkerDescr {
1442 public:
1443 friend class Economy;
1444@@ -47,33 +45,37 @@
1445 const LuaTable& t, const EditorGameBase& egbase);
1446 ~SoldierDescr() override {}
1447
1448- uint32_t get_max_hp_level () const {return max_hp_level_;}
1449- uint32_t get_max_attack_level () const {return max_attack_level_;}
1450- uint32_t get_max_defense_level () const {return max_defense_level_;}
1451- uint32_t get_max_evade_level () const {return max_evade_level_;}
1452-
1453- uint32_t get_base_hp () const {return base_hp_;}
1454- uint32_t get_base_min_attack() const {return min_attack_;}
1455- uint32_t get_base_max_attack() const {return max_attack_;}
1456- uint32_t get_base_defense () const {return defense_;}
1457- uint32_t get_base_evade () const {return evade_;}
1458-
1459- uint32_t get_hp_incr_per_level () const {return hp_incr_;}
1460- uint32_t get_attack_incr_per_level () const {return attack_incr_;}
1461- uint32_t get_defense_incr_per_level() const {return defense_incr_;}
1462- uint32_t get_evade_incr_per_level () const {return evade_incr_;}
1463-
1464- const Image* get_hp_level_pic (uint32_t const level) const {
1465- assert(level <= max_hp_level_); return hp_pics_ [level];
1466+ uint32_t get_max_health_level () const {return health_.max_level;}
1467+ uint32_t get_max_attack_level () const {return attack_.max_level;}
1468+ uint32_t get_max_defense_level () const {return defense_.max_level;}
1469+ uint32_t get_max_evade_level () const {return evade_.max_level;}
1470+
1471+ uint32_t get_base_health () const {return health_.base;}
1472+ uint32_t get_base_min_attack() const {return attack_.base;}
1473+ uint32_t get_base_max_attack() const {return attack_.maximum;}
1474+ uint32_t get_base_defense () const {return defense_.base;}
1475+ uint32_t get_base_evade () const {return evade_.base;}
1476+
1477+ uint32_t get_health_incr_per_level () const {return health_.increase;}
1478+ uint32_t get_attack_incr_per_level () const {return attack_.increase;}
1479+ uint32_t get_defense_incr_per_level() const {return defense_.increase;}
1480+ uint32_t get_evade_incr_per_level () const {return evade_.increase;}
1481+
1482+ const Image* get_health_level_pic(uint32_t const level) const {
1483+ assert(level <= get_max_health_level());
1484+ return health_.images[level];
1485 }
1486- const Image* get_attack_level_pic (uint32_t const level) const {
1487- assert(level <= max_attack_level_); return attack_pics_ [level];
1488+ const Image* get_attack_level_pic(uint32_t const level) const {
1489+ assert(level <= get_max_attack_level());
1490+ return attack_.images[level];
1491 }
1492 const Image* get_defense_level_pic(uint32_t const level) const {
1493- assert(level <= max_defense_level_); return defense_pics_[level];
1494+ assert(level <= get_max_defense_level());
1495+ return defense_.images[level];
1496 }
1497- const Image* get_evade_level_pic (uint32_t const level) const {
1498- assert(level <= max_evade_level_); return evade_pics_ [level];
1499+ const Image* get_evade_level_pic(uint32_t const level) const {
1500+ assert(level <= get_max_evade_level());
1501+ return evade_.images[level];
1502 }
1503
1504 uint32_t get_rand_anim(Game & game, const char * const name) const;
1505@@ -81,36 +83,24 @@
1506 protected:
1507 Bob & create_object() const override;
1508
1509- // start values
1510- uint32_t base_hp_;
1511- uint32_t min_attack_;
1512- uint32_t max_attack_;
1513- uint32_t defense_;
1514- uint32_t evade_;
1515-
1516- // per level increases
1517- uint32_t hp_incr_;
1518- uint32_t attack_incr_;
1519- uint32_t defense_incr_;
1520- uint32_t evade_incr_;
1521-
1522- // max levels
1523- uint32_t max_hp_level_;
1524- uint32_t max_attack_level_;
1525- uint32_t max_defense_level_;
1526- uint32_t max_evade_level_;
1527-
1528- // level pictures
1529- std::vector<const Image* > hp_pics_;
1530- std::vector<const Image* > attack_pics_;
1531- std::vector<const Image* > evade_pics_;
1532- std::vector<const Image* > defense_pics_;
1533- std::vector<std::string> hp_pics_fn_;
1534- std::vector<std::string> attack_pics_fn_;
1535- std::vector<std::string> evade_pics_fn_;
1536- std::vector<std::string> defense_pics_fn_;
1537-
1538- // animation names
1539+private:
1540+ // Health, Attack, Defense and Evade values.
1541+ struct BattleAttribute {
1542+ BattleAttribute(std::unique_ptr<LuaTable> table);
1543+
1544+ uint32_t base; // Base value
1545+ uint32_t maximum; // Maximum value for randomizing attack values
1546+ uint32_t increase; // Per level increase
1547+ uint32_t max_level; // Maximum level
1548+ std::vector<const Image* > images; // Level images
1549+ };
1550+
1551+ BattleAttribute health_;
1552+ BattleAttribute attack_;
1553+ BattleAttribute defense_;
1554+ BattleAttribute evade_;
1555+
1556+ // Battle animation names
1557 std::vector<std::string> attack_success_w_name_;
1558 std::vector<std::string> attack_failure_w_name_;
1559 std::vector<std::string> evade_success_w_name_;
1560@@ -123,7 +113,6 @@
1561 std::vector<std::string> evade_failure_e_name_;
1562 std::vector<std::string> die_e_name_;
1563
1564-private:
1565 // Reads list of animation names from the table and pushes them into result.
1566 void add_battle_animation(std::unique_ptr<LuaTable> table, std::vector<std::string>* result);
1567
1568@@ -145,7 +134,7 @@
1569 enum CombatFlags {
1570 /// Soldier will wait enemies at his building flag. Only for defenders.
1571 CF_DEFEND_STAYHOME = 1,
1572- /// When current hitpoints goes under a fixed percentage, soldier will flee
1573+ /// When current health points drop below a fixed percentage, soldier will flee
1574 /// and heal inside military building
1575 CF_RETREAT_WHEN_INJURED = 2,
1576 /// Attackers would try avoid entering combat with others soldiers but 'flag
1577@@ -165,17 +154,17 @@
1578 void cleanup(EditorGameBase &) override;
1579
1580 void set_level
1581- (uint32_t hp, uint32_t attack, uint32_t defense, uint32_t evade);
1582- void set_hp_level (uint32_t);
1583+ (uint32_t health, uint32_t attack, uint32_t defense, uint32_t evade);
1584+ void set_health_level (uint32_t);
1585 void set_attack_level (uint32_t);
1586 void set_defense_level(uint32_t);
1587 void set_evade_level (uint32_t);
1588 uint32_t get_level (TrainingAttribute) const;
1589- uint32_t get_hp_level () const {return hp_level_;}
1590+ uint32_t get_health_level () const {return health_level_;}
1591 uint32_t get_attack_level () const {return attack_level_;}
1592 uint32_t get_defense_level() const {return defense_level_;}
1593 uint32_t get_evade_level () const {return evade_level_;}
1594- uint32_t get_total_level () const {return hp_level_ + attack_level_ + defense_level_ + evade_level_;}
1595+ uint32_t get_total_level () const {return health_level_ + attack_level_ + defense_level_ + evade_level_;}
1596
1597 /// Automatically select a task.
1598 void init_auto_task(Game &) override;
1599@@ -188,15 +177,15 @@
1600 (const TribeDescr &, uint32_t & w, uint32_t & h);
1601 void draw_info_icon(RenderTarget &, Point, bool anchor_below) const;
1602
1603- uint32_t get_current_hitpoints() const {return hp_current_;}
1604- uint32_t get_max_hitpoints() const;
1605+ uint32_t get_current_health() const {return current_health_;}
1606+ uint32_t get_max_health() const;
1607 uint32_t get_min_attack() const;
1608 uint32_t get_max_attack() const;
1609 uint32_t get_defense() const;
1610 uint32_t get_evade() const;
1611
1612- const Image* get_hp_level_pic () const {
1613- return descr().get_hp_level_pic (hp_level_);
1614+ const Image* get_health_level_pic () const {
1615+ return descr().get_health_level_pic(health_level_);
1616 }
1617 const Image* get_attack_level_pic () const {
1618 return descr().get_attack_level_pic (attack_level_);
1619@@ -208,15 +197,15 @@
1620 return descr().get_evade_level_pic (evade_level_);
1621 }
1622
1623- int32_t get_training_attribute(uint32_t attr) const override;
1624+ int32_t get_training_attribute(TrainingAttribute attr) const override;
1625
1626 /// Sets a random animation of desired type and start playing it.
1627 void start_animation
1628 (EditorGameBase &, char const * animname, uint32_t time);
1629
1630- /// Heal quantity of hit points instantly
1631+ /// Heal quantity of health points instantly
1632 void heal (uint32_t);
1633- void damage (uint32_t); /// Damage quantity of hit points
1634+ void damage (uint32_t); /// Damage quantity of health points
1635
1636 void log_general_info(const EditorGameBase &) override;
1637
1638@@ -262,8 +251,8 @@
1639 bool is_evict_allowed() override;
1640
1641 private:
1642- uint32_t hp_current_;
1643- uint32_t hp_level_;
1644+ uint32_t current_health_;
1645+ uint32_t health_level_;
1646 uint32_t attack_level_;
1647 uint32_t defense_level_;
1648 uint32_t evade_level_;
1649@@ -284,7 +273,7 @@
1650 */
1651 Battle * battle_;
1652
1653- static constexpr uint8_t kSoldierHpBarWidth = 13;
1654+ static constexpr uint8_t kSoldierHealthBarWidth = 13;
1655
1656 /// Number of consecutive blocked signals until the soldiers are considered permanently stuck
1657 static constexpr uint8_t kBockCountIsStuck = 10;
1658
1659=== modified file 'src/logic/map_objects/tribes/training_attribute.h'
1660--- src/logic/map_objects/tribes/training_attribute.h 2015-11-28 22:29:26 +0000
1661+++ src/logic/map_objects/tribes/training_attribute.h 2016-03-09 16:59:37 +0000
1662@@ -20,18 +20,20 @@
1663 #ifndef WL_LOGIC_MAP_OBJECTS_TRIBES_TRAINING_ATTRIBUTE_H
1664 #define WL_LOGIC_MAP_OBJECTS_TRIBES_TRAINING_ATTRIBUTE_H
1665
1666+#include <cstdint>
1667+
1668 namespace Widelands {
1669
1670 /**
1671 * Indices for specific, individual attributes that \ref MapObject instances
1672 * may have. Used in conjunction with \ref Requirements.
1673 */
1674-enum TrainingAttribute {
1675- atrHP = 0,
1676- atrAttack,
1677- atrDefense,
1678- atrEvade,
1679- atrTotal = 100
1680+enum class TrainingAttribute : uint8_t {
1681+ kHealth = 0,
1682+ kAttack,
1683+ kDefense,
1684+ kEvade,
1685+ kTotal = 100
1686 };
1687
1688 }
1689
1690=== modified file 'src/logic/map_objects/tribes/trainingsite.cc'
1691--- src/logic/map_objects/tribes/trainingsite.cc 2016-02-09 07:42:38 +0000
1692+++ src/logic/map_objects/tribes/trainingsite.cc 2016-03-09 16:59:37 +0000
1693@@ -49,15 +49,15 @@
1694 num_soldiers_ (table.get_int("soldier_capacity")),
1695 max_stall_ (table.get_int("trainer_patience")),
1696
1697- train_hp_ (false),
1698+ train_health_ (false),
1699 train_attack_ (false),
1700 train_defense_ (false),
1701 train_evade_ (false),
1702- min_hp_ (0),
1703+ min_health_ (0),
1704 min_attack_ (0),
1705 min_defense_ (0),
1706 min_evade_ (0),
1707- max_hp_ (0),
1708+ max_health_ (0),
1709 max_attack_ (0),
1710 max_defense_ (0),
1711 max_evade_ (0)
1712@@ -68,12 +68,12 @@
1713 // These sections also seem redundant. Eliminate them (having the
1714 // programs should be enough).
1715 std::unique_ptr<LuaTable> items_table;
1716- if (table.has_key("soldier hp")) {
1717- items_table = table.get_table("soldier hp");
1718- train_hp_ = true;
1719- min_hp_ = items_table->get_int("min_level");
1720- max_hp_ = items_table->get_int("max_level");
1721- add_training_inputs(*items_table.get(), &food_hp_, &weapons_hp_);
1722+ if (table.has_key("soldier health")) {
1723+ items_table = table.get_table("soldier health");
1724+ train_health_ = true;
1725+ min_health_ = items_table->get_int("min_level");
1726+ max_health_ = items_table->get_int("max_level");
1727+ add_training_inputs(*items_table.get(), &food_health_, &weapons_health_);
1728 }
1729
1730 if (table.has_key("soldier attack")) {
1731@@ -114,15 +114,15 @@
1732 */
1733 int32_t TrainingSiteDescr::get_min_level(const TrainingAttribute at) const {
1734 switch (at) {
1735- case atrHP:
1736- return min_hp_;
1737- case atrAttack:
1738+ case TrainingAttribute::kHealth:
1739+ return min_health_;
1740+ case TrainingAttribute::kAttack:
1741 return min_attack_;
1742- case atrDefense:
1743+ case TrainingAttribute::kDefense:
1744 return min_defense_;
1745- case atrEvade:
1746+ case TrainingAttribute::kEvade:
1747 return min_evade_;
1748- case atrTotal:
1749+ case TrainingAttribute::kTotal:
1750 throw wexception("Unknown attribute value!");
1751 }
1752 NEVER_HERE();
1753@@ -136,15 +136,15 @@
1754 */
1755 int32_t TrainingSiteDescr::get_max_level(const TrainingAttribute at) const {
1756 switch (at) {
1757- case atrHP:
1758- return max_hp_;
1759- case atrAttack:
1760+ case TrainingAttribute::kHealth:
1761+ return max_health_;
1762+ case TrainingAttribute::kAttack:
1763 return max_attack_;
1764- case atrDefense:
1765+ case TrainingAttribute::kDefense:
1766 return max_defense_;
1767- case atrEvade:
1768+ case TrainingAttribute::kEvade:
1769 return max_evade_;
1770- case atrTotal:
1771+ case TrainingAttribute::kTotal:
1772 throw wexception("Unknown attribute value!");
1773 }
1774 NEVER_HERE();
1775@@ -201,14 +201,14 @@
1776 training_failure_count_.clear();
1777 max_stall_val_ = training_state_multiplier_ * d.get_max_stall();
1778
1779- if (d.get_train_hp())
1780- init_kick_state(atrHP, d);
1781+ if (d.get_train_health())
1782+ init_kick_state(TrainingAttribute::kHealth, d);
1783 if (d.get_train_attack())
1784- init_kick_state(atrAttack, d);
1785+ init_kick_state(TrainingAttribute::kAttack, d);
1786 if (d.get_train_defense())
1787- init_kick_state(atrDefense, d);
1788+ init_kick_state(TrainingAttribute::kDefense, d);
1789 if (d.get_train_evade())
1790- init_kick_state(atrEvade, d);
1791+ init_kick_state(TrainingAttribute::kEvade, d);
1792 }
1793 void
1794 TrainingSite::init_kick_state(const TrainingAttribute & art, const TrainingSiteDescr & d)
1795@@ -322,27 +322,27 @@
1796 if (descr().get_train_attack())
1797 r.add
1798 (RequireAttribute
1799- (atrAttack,
1800- descr().get_min_level(atrAttack),
1801- descr().get_max_level(atrAttack)));
1802+ (TrainingAttribute::kAttack,
1803+ descr().get_min_level(TrainingAttribute::kAttack),
1804+ descr().get_max_level(TrainingAttribute::kAttack)));
1805 if (descr().get_train_defense())
1806 r.add
1807 (RequireAttribute
1808- (atrDefense,
1809- descr().get_min_level(atrDefense),
1810- descr().get_max_level(atrDefense)));
1811+ (TrainingAttribute::kDefense,
1812+ descr().get_min_level(TrainingAttribute::kDefense),
1813+ descr().get_max_level(TrainingAttribute::kDefense)));
1814 if (descr().get_train_evade())
1815 r.add
1816 (RequireAttribute
1817- (atrEvade,
1818- descr().get_min_level(atrEvade),
1819- descr().get_max_level(atrEvade)));
1820- if (descr().get_train_hp())
1821+ (TrainingAttribute::kEvade,
1822+ descr().get_min_level(TrainingAttribute::kEvade),
1823+ descr().get_max_level(TrainingAttribute::kEvade)));
1824+ if (descr().get_train_health())
1825 r.add
1826 (RequireAttribute
1827- (atrHP,
1828- descr().get_min_level(atrHP),
1829- descr().get_max_level(atrHP)));
1830+ (TrainingAttribute::kHealth,
1831+ descr().get_min_level(TrainingAttribute::kHealth),
1832+ descr().get_max_level(TrainingAttribute::kHealth)));
1833
1834 soldier_request_->set_requirements(r);
1835 }
1836@@ -506,7 +506,7 @@
1837
1838 for (uint32_t i = 0; i < soldiers_.size(); ++i)
1839 {
1840- uint32_t this_soldier_level = soldiers_[i]->get_level(atrTotal);
1841+ uint32_t this_soldier_level = soldiers_[i]->get_level(TrainingAttribute::kTotal);
1842
1843 bool this_soldier_is_safe = false;
1844 if (this_soldier_level <= highest_soldier_level_seen)
1845@@ -775,19 +775,19 @@
1846
1847 // TODO(unknown): This is currently hardcoded for "soldier" but it should allow any
1848 // soldier type name.
1849- if (descr().get_train_hp())
1850- add_upgrade(atrHP, "upgrade_soldier_hp_");
1851+ if (descr().get_train_health())
1852+ add_upgrade(TrainingAttribute::kHealth, "upgrade_soldier_health_");
1853 if (descr().get_train_attack())
1854- add_upgrade(atrAttack, "upgrade_soldier_attack_");
1855+ add_upgrade(TrainingAttribute::kAttack, "upgrade_soldier_attack_");
1856 if (descr().get_train_defense())
1857- add_upgrade(atrDefense, "upgrade_soldier_defense_");
1858+ add_upgrade(TrainingAttribute::kDefense, "upgrade_soldier_defense_");
1859 if (descr().get_train_evade())
1860- add_upgrade(atrEvade, "upgrade_soldier_evade_");
1861+ add_upgrade(TrainingAttribute::kEvade, "upgrade_soldier_evade_");
1862 }
1863
1864
1865 void
1866-TrainingSite::training_attempted(uint32_t type, uint32_t level)
1867+TrainingSite::training_attempted(TrainingAttribute type, uint32_t level)
1868 {
1869 TypeAndLevel key(type, level);
1870 if (training_failure_count_.find(key) == training_failure_count_.end())
1871@@ -801,7 +801,7 @@
1872 */
1873
1874 void
1875-TrainingSite::training_successful(uint32_t type, uint32_t level)
1876+TrainingSite::training_successful(TrainingAttribute type, uint32_t level)
1877 {
1878 TypeAndLevel key(type, level);
1879 // Here I assume that key exists: training has been attempted before it can succeed.
1880
1881=== modified file 'src/logic/map_objects/tribes/trainingsite.h'
1882--- src/logic/map_objects/tribes/trainingsite.h 2016-02-09 07:42:38 +0000
1883+++ src/logic/map_objects/tribes/trainingsite.h 2016-03-09 16:59:37 +0000
1884@@ -41,7 +41,7 @@
1885 uint32_t get_max_number_of_soldiers() const {
1886 return num_soldiers_;
1887 }
1888- bool get_train_hp () const {return train_hp_;}
1889+ bool get_train_health () const {return train_health_;}
1890 bool get_train_attack () const {return train_attack_;}
1891 bool get_train_defense() const {return train_defense_;}
1892 bool get_train_evade () const {return train_evade_;}
1893@@ -50,8 +50,8 @@
1894 int32_t get_max_level(TrainingAttribute) const;
1895 int32_t get_max_stall() const;
1896
1897- const std::vector<std::vector<std::string>>& get_food_hp() const {
1898- return food_hp_;
1899+ const std::vector<std::vector<std::string>>& get_food_health() const {
1900+ return food_health_;
1901 }
1902 const std::vector<std::vector<std::string>>& get_food_attack() const {
1903 return food_attack_;
1904@@ -62,8 +62,8 @@
1905 const std::vector<std::vector<std::string>>& get_food_evade() const {
1906 return food_evade_;
1907 }
1908- const std::vector<std::string>& get_weapons_hp() const {
1909- return weapons_hp_;
1910+ const std::vector<std::string>& get_weapons_health() const {
1911+ return weapons_health_;
1912 }
1913 const std::vector<std::string>& get_weapons_attack() const {
1914 return weapons_attack_;
1915@@ -77,7 +77,7 @@
1916
1917 private:
1918 // Read the table to add needed food and weapons for training a property.
1919- // Properties are hp, attack, defense, and evade.
1920+ // Properties are health, attack, defense, and evade.
1921 void add_training_inputs(const LuaTable& table,
1922 std::vector<std::vector<std::string>>* food, std::vector<std::string>* weapons);
1923
1924@@ -88,8 +88,8 @@
1925 uint32_t num_soldiers_;
1926 /** Number of rounds w/o successful training, after which a soldier is kicked out.**/
1927 uint32_t max_stall_;
1928- /** Whether this site can train hitpoints*/
1929- bool train_hp_;
1930+ /** Whether this site can train health*/
1931+ bool train_health_;
1932 /** Whether this site can train attack*/
1933 bool train_attack_;
1934 /** Whether this site can train defense*/
1935@@ -97,8 +97,8 @@
1936 /** Whether this site can train evasion*/
1937 bool train_evade_;
1938
1939- /** Minimum hitpoints to which a soldier can drop at this site*/
1940- int32_t min_hp_;
1941+ /** Minimum health to which a soldier can drop at this site*/
1942+ int32_t min_health_;
1943 /** Minimum attacks to which a soldier can drop at this site*/
1944 int32_t min_attack_;
1945 /** Minimum defense to which a soldier can drop at this site*/
1946@@ -106,8 +106,8 @@
1947 /** Minimum evasion to which a soldier can drop at this site*/
1948 int32_t min_evade_;
1949
1950- /** Maximum hitpoints a soldier can acquire at this site*/
1951- int32_t max_hp_;
1952+ /** Maximum health a soldier can acquire at this site*/
1953+ int32_t max_health_;
1954 /** Maximum attack a soldier can acquire at this site*/
1955 int32_t max_attack_;
1956 /** Maximum defense a soldier can acquire at this site*/
1957@@ -116,11 +116,11 @@
1958 int32_t max_evade_;
1959
1960 // For building help
1961- std::vector<std::vector<std::string>> food_hp_;
1962+ std::vector<std::vector<std::string>> food_health_;
1963 std::vector<std::vector<std::string>> food_attack_;
1964 std::vector<std::vector<std::string>> food_defense_;
1965 std::vector<std::vector<std::string>> food_evade_;
1966- std::vector<std::string> weapons_hp_;
1967+ std::vector<std::string> weapons_health_;
1968 std::vector<std::string> weapons_attack_;
1969 std::vector<std::string> weapons_defense_;
1970 std::vector<std::string> weapons_evade_;
1971@@ -130,7 +130,7 @@
1972
1973 /**
1974 * A building to change soldiers' abilities.
1975- * Soldiers can gain hitpoints, or experience in attack, defense and evasion.
1976+ * Soldiers can gain health, or experience in attack, defense and evasion.
1977 *
1978 * \note A training site does not change influence areas. If you lose the
1979 * surrounding strongholds, the training site will burn even if it
1980@@ -192,8 +192,8 @@
1981 void set_pri(enum TrainingAttribute atr, int32_t prio);
1982
1983 // These are for premature soldier kick-out
1984- void training_attempted(uint32_t type, uint32_t level);
1985- void training_successful(uint32_t type, uint32_t level);
1986+ void training_attempted(TrainingAttribute type, uint32_t level);
1987+ void training_successful(TrainingAttribute type, uint32_t level);
1988 void training_done();
1989
1990
1991@@ -240,7 +240,7 @@
1992 // These are used for kicking out soldiers prematurely
1993 static const uint32_t training_state_multiplier_;
1994 // Unuque key to address each training level of each war art
1995- using TypeAndLevel = std::pair<uint16_t, uint16_t>;
1996+ using TypeAndLevel = std::pair<TrainingAttribute, uint16_t>;
1997 // First entry is the "stallness", second is a bool
1998 using FailAndPresence = std::pair<uint16_t, uint8_t>; // first might wrap in a long play..
1999 using TrainFailCount = std::map<TypeAndLevel, FailAndPresence>;
2000
2001=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
2002--- src/logic/map_objects/tribes/warehouse.cc 2016-02-18 08:42:46 +0000
2003+++ src/logic/map_objects/tribes/warehouse.cc 2016-03-09 16:59:37 +0000
2004@@ -693,13 +693,13 @@
2005 Soldier * soldier = static_cast<Soldier *>(*it);
2006
2007 // Soldier dead ...
2008- if (!soldier || soldier->get_current_hitpoints() == 0) {
2009+ if (!soldier || soldier->get_current_health() == 0) {
2010 it = soldiers.erase(it);
2011 supply_->remove_workers(soldier_index, 1);
2012 continue;
2013 }
2014
2015- if (soldier->get_current_hitpoints() < soldier->get_max_hitpoints()) {
2016+ if (soldier->get_current_health() < soldier->get_max_health()) {
2017 soldier->heal(total_heal);
2018 continue;
2019 }
2020
2021=== modified file 'src/logic/player.cc'
2022--- src/logic/player.cc 2016-03-02 16:30:42 +0000
2023+++ src/logic/player.cc 2016-03-09 16:59:37 +0000
2024@@ -872,10 +872,9 @@
2025 ==========
2026 */
2027 void Player::change_training_options
2028- (TrainingSite & trainingsite, int32_t const atr, int32_t const val)
2029+ (TrainingSite & trainingsite, TrainingAttribute attr, int32_t const val)
2030 {
2031 if (trainingsite.get_owner() == this) {
2032- TrainingAttribute const attr = static_cast<TrainingAttribute>(atr);
2033 trainingsite.set_pri(attr, trainingsite.get_pri(attr) + val);
2034 }
2035 }
2036
2037=== modified file 'src/logic/player.h'
2038--- src/logic/player.h 2016-02-21 20:02:09 +0000
2039+++ src/logic/player.h 2016-03-09 16:59:37 +0000
2040@@ -489,7 +489,7 @@
2041
2042 // Military stuff
2043 void drop_soldier(PlayerImmovable &, Soldier &);
2044- void change_training_options(TrainingSite &, int32_t atr, int32_t val);
2045+ void change_training_options(TrainingSite &, TrainingAttribute attr, int32_t val);
2046
2047 uint32_t find_attack_soldiers
2048 (Flag &,
2049
2050=== modified file 'src/logic/playercommand.cc'
2051--- src/logic/playercommand.cc 2016-02-16 13:18:59 +0000
2052+++ src/logic/playercommand.cc 2016-03-09 16:59:37 +0000
2053@@ -1560,26 +1560,25 @@
2054 PlayerCommand (0, des.unsigned_8())
2055 {
2056 serial = des.unsigned_32(); // Serial of the building
2057- attribute = des.unsigned_16(); // Attribute to modify
2058+ attribute = static_cast<TrainingAttribute>(des.unsigned_8()); // Attribute to modify
2059 value = des.unsigned_16(); // New vale
2060 }
2061
2062 void CmdChangeTrainingOptions::execute (Game & game)
2063 {
2064 if (upcast(TrainingSite, trainingsite, game.objects().get_object(serial)))
2065- game.player(sender()).change_training_options
2066- (*trainingsite, attribute, value);
2067+ game.player(sender()).change_training_options(*trainingsite, attribute, value);
2068 }
2069
2070 void CmdChangeTrainingOptions::serialize (StreamWrite & ser) {
2071 ser.unsigned_8 (PLCMD_CHANGETRAININGOPTIONS);
2072 ser.unsigned_8 (sender());
2073 ser.unsigned_32(serial);
2074- ser.unsigned_16(attribute);
2075+ ser.unsigned_8(static_cast<uint8_t>(attribute));
2076 ser.unsigned_16(value);
2077 }
2078
2079-constexpr uint16_t kCurrentPacketVersionChangeTrainingOptions = 1;
2080+constexpr uint16_t kCurrentPacketVersionChangeTrainingOptions = 2;
2081
2082 void CmdChangeTrainingOptions::read
2083 (FileRead & fr, EditorGameBase & egbase, MapObjectLoader & mol)
2084@@ -1589,7 +1588,7 @@
2085 if (packet_version == kCurrentPacketVersionChangeTrainingOptions) {
2086 PlayerCommand::read(fr, egbase, mol);
2087 serial = get_object_serial_or_zero<TrainingSite>(fr.unsigned_32(), mol);
2088- attribute = fr.unsigned_16();
2089+ attribute = static_cast<TrainingAttribute>(fr.unsigned_8());
2090 value = fr.unsigned_16();
2091 } else {
2092 throw UnhandledVersionError("CmdChangeTrainingOptions",
2093@@ -1611,7 +1610,7 @@
2094 // Now serial
2095 fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial)));
2096
2097- fw.unsigned_16(attribute);
2098+ fw.unsigned_8(static_cast<uint8_t>(attribute));
2099 fw.unsigned_16(value);
2100 }
2101
2102
2103=== modified file 'src/logic/playercommand.h'
2104--- src/logic/playercommand.h 2016-02-16 13:18:59 +0000
2105+++ src/logic/playercommand.h 2016-03-09 16:59:37 +0000
2106@@ -579,12 +579,13 @@
2107 };
2108
2109 struct CmdChangeTrainingOptions : public PlayerCommand {
2110- CmdChangeTrainingOptions() : PlayerCommand(), serial(0), attribute(0), value(0) {} // For savegame loading
2111+ CmdChangeTrainingOptions() : PlayerCommand(),
2112+ serial(0), attribute(TrainingAttribute::kHealth), value(0) {} // For savegame loading
2113 CmdChangeTrainingOptions
2114 (const uint32_t t,
2115 const PlayerNumber p,
2116 TrainingSite & ts,
2117- const int32_t at,
2118+ const TrainingAttribute at,
2119 const int32_t val)
2120 : PlayerCommand(t, p), serial(ts.serial()), attribute(at), value(val)
2121 {}
2122@@ -602,7 +603,7 @@
2123
2124 private:
2125 Serial serial;
2126- int32_t attribute;
2127+ TrainingAttribute attribute;
2128 int32_t value;
2129 };
2130
2131
2132=== modified file 'src/logic/widelands.h'
2133--- src/logic/widelands.h 2016-01-01 17:35:01 +0000
2134+++ src/logic/widelands.h 2016-03-09 16:59:37 +0000
2135@@ -65,18 +65,18 @@
2136 constexpr DescriptionIndex kNoResource = INVALID_INDEX - 1;
2137
2138 struct SoldierStrength {
2139- uint8_t hp, attack, defense, evade;
2140+ uint8_t health, attack, defense, evade;
2141 bool operator== (const SoldierStrength & other) const {
2142 return
2143- hp == other.hp &&
2144+ health == other.health &&
2145 attack == other.attack &&
2146 defense == other.defense &&
2147 evade == other.evade;
2148 }
2149 bool operator< (const SoldierStrength & other) const {
2150 return
2151- hp < other.hp ||
2152- (hp == other.hp &&
2153+ health < other.health ||
2154+ (health == other.health &&
2155 (attack < other.attack ||
2156 (attack == other.attack &&
2157 (defense < other.defense ||
2158
2159=== modified file 'src/map_io/map_buildingdata_packet.cc'
2160--- src/map_io/map_buildingdata_packet.cc 2016-03-02 10:04:54 +0000
2161+++ src/map_io/map_buildingdata_packet.cc 2016-03-09 16:59:37 +0000
2162@@ -62,7 +62,7 @@
2163 constexpr uint16_t kCurrentPacketVersionWarehouse = 6;
2164 constexpr uint16_t kCurrentPacketVersionMilitarysite = 5;
2165 constexpr uint16_t kCurrentPacketVersionProductionsite = 5;
2166-constexpr uint16_t kCurrentPacketVersionTrainingsite = 4;
2167+constexpr uint16_t kCurrentPacketVersionTrainingsite = 5;
2168
2169 void MapBuildingdataPacket::read
2170 (FileSystem & fs,
2171@@ -562,7 +562,8 @@
2172
2173 uint16_t reqmin = fr.unsigned_16();
2174 uint16_t reqmax = fr.unsigned_16();
2175- militarysite.soldier_upgrade_requirements_ = RequireAttribute(atrTotal, reqmin, reqmax);
2176+ militarysite.soldier_upgrade_requirements_ =
2177+ RequireAttribute(TrainingAttribute::kTotal, reqmin, reqmax);
2178 militarysite.soldier_preference_ = static_cast<MilitarySite::SoldierPreference>(fr.unsigned_8());
2179 militarysite.next_swap_soldiers_time_ = fr.signed_32();
2180 militarysite.soldier_upgrade_try_ = 0 != fr.unsigned_8() ? true : false;
2181@@ -829,13 +830,35 @@
2182 uint16_t mapsize = fr.unsigned_16(); // map of training levels (not _the_ map)
2183 while (mapsize)
2184 {
2185- uint16_t traintype = fr.unsigned_16();
2186+ // Get the training attribute and check if it is a valid enum member
2187+ // We use a temp value, because the static_cast to the enum might be undefined.
2188+ uint8_t temp_traintype = fr.unsigned_8();
2189+ switch (temp_traintype) {
2190+ case static_cast<uint8_t>(TrainingAttribute::kHealth):
2191+ case static_cast<uint8_t>(TrainingAttribute::kAttack):
2192+ case static_cast<uint8_t>(TrainingAttribute::kDefense):
2193+ case static_cast<uint8_t>(TrainingAttribute::kEvade):
2194+ case static_cast<uint8_t>(TrainingAttribute::kTotal):
2195+ break;
2196+ default:
2197+ throw GameDataError
2198+ (
2199+ "expected kHealth (%u), kAttack (%u), kDefense (%u), kEvade "
2200+ "(%u) or kTotal (%u) but found unknown attribute value (%u)",
2201+ TrainingAttribute::kHealth,
2202+ TrainingAttribute::kAttack,
2203+ TrainingAttribute::kDefense,
2204+ TrainingAttribute::kEvade,
2205+ TrainingAttribute::kTotal,
2206+ temp_traintype);
2207+ }
2208+ TrainingAttribute traintype = static_cast<TrainingAttribute>(temp_traintype);
2209 uint16_t trainlevel = fr.unsigned_16();
2210 uint16_t trainstall = fr.unsigned_16();
2211 uint16_t spresence = fr.unsigned_8();
2212 mapsize--;
2213- std::pair<uint16_t, uint8_t> t = std::make_pair(trainstall, spresence);
2214- trainingsite.training_failure_count_[std::make_pair(traintype, trainlevel)] = t;
2215+ trainingsite.training_failure_count_[std::make_pair(traintype, trainlevel)] =
2216+ std::make_pair(trainstall, spresence);
2217 }
2218 } else {
2219 throw UnhandledVersionError("MapBuildingdataPacket - Trainingsite",
2220@@ -1275,7 +1298,7 @@
2221 fw.unsigned_8(trainingsite.upgrades_.size());
2222 for (uint8_t i = 0; i < trainingsite.upgrades_.size(); ++i) {
2223 const TrainingSite::Upgrade & upgrade = trainingsite.upgrades_[i];
2224- fw.unsigned_8(upgrade.attribute);
2225+ fw.unsigned_8(static_cast<uint8_t>(upgrade.attribute));
2226 fw.unsigned_8(upgrade.prio);
2227 fw.unsigned_8(upgrade.credit);
2228 fw.signed_32(upgrade.lastattempt);
2229@@ -1290,7 +1313,7 @@
2230 (TrainingSite::TrainFailCount::const_iterator i = trainingsite.training_failure_count_.begin();
2231 i != trainingsite.training_failure_count_.end(); i++)
2232 {
2233- fw.unsigned_16(i->first.first);
2234+ fw.unsigned_8(static_cast<uint8_t>(i->first.first));
2235 fw.unsigned_16(i->first.second);
2236 fw.unsigned_16(i->second.first);
2237 fw.unsigned_8(i->second.second);
2238
2239=== modified file 'src/scripting/lua_map.cc'
2240--- src/scripting/lua_map.cc 2016-02-27 08:43:39 +0000
2241+++ src/scripting/lua_map.cc 2016-03-09 16:59:37 +0000
2242@@ -112,31 +112,31 @@
2243 }
2244
2245 struct SoldierMapDescr {
2246- SoldierMapDescr(uint8_t ghp, uint8_t gat, uint8_t gde, uint8_t gev)
2247- : hp(ghp), at(gat), de(gde), ev(gev) {
2248+ SoldierMapDescr(uint8_t init_health, uint8_t init_attack, uint8_t init_defense, uint8_t init_evade)
2249+ : health(init_health), attack(init_attack), defense(init_defense), evade(init_evade) {
2250 }
2251- SoldierMapDescr() : hp(0), at(0), de(0), ev(0) {
2252+ SoldierMapDescr() : health(0), attack(0), defense(0), evade(0) {
2253 }
2254
2255- uint8_t hp;
2256- uint8_t at;
2257- uint8_t de;
2258- uint8_t ev;
2259+ uint8_t health;
2260+ uint8_t attack;
2261+ uint8_t defense;
2262+ uint8_t evade;
2263
2264 bool operator<(const SoldierMapDescr& ot) const {
2265- bool hp_eq = hp == ot.hp;
2266- bool at_eq = at == ot.at;
2267- bool de_eq = de == ot.de;
2268- if (hp_eq && at_eq && de_eq)
2269- return ev < ot.ev;
2270- if (hp_eq && at_eq)
2271- return de < ot.de;
2272- if (hp_eq)
2273- return at < ot.at;
2274- return hp < ot.hp;
2275+ bool equal_health = health == ot.health;
2276+ bool equal_attack = attack == ot.attack;
2277+ bool equal_defense = defense == ot.defense;
2278+ if (equal_health && equal_attack && equal_defense)
2279+ return evade < ot.evade;
2280+ if (equal_health && equal_attack)
2281+ return defense < ot.defense;
2282+ if (equal_health)
2283+ return attack < ot.attack;
2284+ return health < ot.health;
2285 }
2286 bool operator == (const SoldierMapDescr& ot) const {
2287- if (hp == ot.hp && at == ot.at && de == ot.de && ev == ot.ev)
2288+ if (health == ot.health && attack == ot.attack && defense == ot.defense && evade == ot.evade)
2289 return true;
2290 return false;
2291 }
2292@@ -375,43 +375,43 @@
2293 return 0;
2294 }
2295
2296-// Unpacks the Lua table of the form {hp, at, de, ev} at the stack index
2297+// Unpacks the Lua table of the form {health, attack, defense, evade} at the stack index
2298 // 'table_index' into a SoldierMapDescr struct.
2299 SoldierMapDescr unbox_lua_soldier_description(lua_State* L, int table_index, const SoldierDescr& sd) {
2300 SoldierMapDescr soldier_descr;
2301
2302 lua_pushuint32(L, 1);
2303 lua_rawget(L, table_index);
2304- soldier_descr.hp = luaL_checkuint32(L, -1);
2305+ soldier_descr.health = luaL_checkuint32(L, -1);
2306 lua_pop(L, 1);
2307- if (soldier_descr.hp > sd.get_max_hp_level())
2308+ if (soldier_descr.health > sd.get_max_health_level())
2309 report_error
2310- (L, "hp level (%i) > max hp level (%i)", soldier_descr.hp, sd.get_max_hp_level());
2311+ (L, "health level (%i) > max health level (%i)", soldier_descr.health, sd.get_max_health_level());
2312
2313 lua_pushuint32(L, 2);
2314 lua_rawget(L, table_index);
2315- soldier_descr.at = luaL_checkuint32(L, -1);
2316+ soldier_descr.attack = luaL_checkuint32(L, -1);
2317 lua_pop(L, 1);
2318- if (soldier_descr.at > sd.get_max_attack_level())
2319+ if (soldier_descr.attack > sd.get_max_attack_level())
2320 report_error
2321- (L, "attack level (%i) > max attack level (%i)", soldier_descr.at, sd.get_max_attack_level());
2322+ (L, "attack level (%i) > max attack level (%i)", soldier_descr.attack, sd.get_max_attack_level());
2323
2324 lua_pushuint32(L, 3);
2325 lua_rawget(L, table_index);
2326- soldier_descr.de = luaL_checkuint32(L, -1);
2327+ soldier_descr.defense = luaL_checkuint32(L, -1);
2328 lua_pop(L, 1);
2329- if (soldier_descr.de > sd.get_max_defense_level())
2330+ if (soldier_descr.defense > sd.get_max_defense_level())
2331 report_error
2332- (L, "defense level (%i) > max defense level (%i)", soldier_descr.de,
2333+ (L, "defense level (%i) > max defense level (%i)", soldier_descr.defense,
2334 sd.get_max_defense_level());
2335
2336 lua_pushuint32(L, 4);
2337 lua_rawget(L, table_index);
2338- soldier_descr.ev = luaL_checkuint32(L, -1);
2339+ soldier_descr.evade = luaL_checkuint32(L, -1);
2340 lua_pop(L, 1);
2341- if (soldier_descr.ev > sd.get_max_evade_level())
2342+ if (soldier_descr.evade > sd.get_max_evade_level())
2343 report_error
2344- (L, "evade level (%i) > max evade level (%i)", soldier_descr.ev, sd.get_max_evade_level());
2345+ (L, "evade level (%i) > max evade level (%i)", soldier_descr.evade, sd.get_max_evade_level());
2346
2347 return soldier_descr;
2348 }
2349@@ -451,7 +451,7 @@
2350 SoldiersMap hist;
2351 for (const Soldier* s : soldiers) {
2352 SoldierMapDescr sd
2353- (s->get_hp_level(), s->get_attack_level(),
2354+ (s->get_health_level(), s->get_attack_level(),
2355 s->get_defense_level(), s->get_evade_level());
2356
2357 SoldiersMap::iterator i = hist.find(sd);
2358@@ -469,10 +469,10 @@
2359 lua_pushuint32(L, idx); \
2360 lua_pushuint32(L, i.first.name); \
2361 lua_rawset(L, -3);
2362- PUSHLEVEL(1, hp);
2363- PUSHLEVEL(2, at);
2364- PUSHLEVEL(3, de);
2365- PUSHLEVEL(4, ev);
2366+ PUSHLEVEL(1, health);
2367+ PUSHLEVEL(2, attack);
2368+ PUSHLEVEL(3, defense);
2369+ PUSHLEVEL(4, evade);
2370 #undef PUSHLEVEL
2371
2372 lua_pushuint32(L, i.second);
2373@@ -487,7 +487,7 @@
2374 uint32_t rv = 0;
2375 for (const Soldier* s : soldiers) {
2376 SoldierMapDescr sd
2377- (s->get_hp_level(), s->get_attack_level(), s->get_defense_level(), s->get_evade_level());
2378+ (s->get_health_level(), s->get_attack_level(), s->get_defense_level(), s->get_evade_level());
2379 if (sd == wanted)
2380 ++rv;
2381 }
2382@@ -514,7 +514,7 @@
2383 SoldiersMap hist;
2384 for (const Soldier* s : curs) {
2385 SoldierMapDescr sd
2386- (s->get_hp_level(), s->get_attack_level(),
2387+ (s->get_health_level(), s->get_attack_level(),
2388 s->get_defense_level(), s->get_evade_level());
2389
2390 SoldiersMap::iterator i = hist.find(sd);
2391@@ -539,7 +539,7 @@
2392 while (d) {
2393 for (Soldier* s : sc->stationed_soldiers()) {
2394 SoldierMapDescr is
2395- (s->get_hp_level(), s->get_attack_level(),
2396+ (s->get_health_level(), s->get_attack_level(),
2397 s->get_defense_level(), s->get_evade_level());
2398
2399 if (is == sp.first) {
2400@@ -555,7 +555,7 @@
2401 Soldier& soldier = dynamic_cast<Soldier&>
2402 (soldier_descr.create(egbase, *owner, nullptr, building_position));
2403 soldier.set_level
2404- (sp.first.hp, sp.first.at, sp.first.de, sp.first.ev);
2405+ (sp.first.health, sp.first.attack, sp.first.defense, sp.first.evade);
2406 if (sc->incorporate_soldier(egbase, soldier)) {
2407 soldier.remove(egbase);
2408 report_error(L, "No space left for soldier!");
2409@@ -807,7 +807,7 @@
2410 kind in this building.
2411
2412 A soldier description is a :class:`array` that contains the level for
2413- hitpoints, attack, defense and evade (in this order). An usage example:
2414+ health, attack, defense and evade (in this order). A usage example:
2415
2416 .. code-block:: lua
2417
2418@@ -2180,20 +2180,20 @@
2419 PROP_RO(LuaTrainingSiteDescription, food_attack),
2420 PROP_RO(LuaTrainingSiteDescription, food_defense),
2421 PROP_RO(LuaTrainingSiteDescription, food_evade),
2422- PROP_RO(LuaTrainingSiteDescription, food_hp),
2423+ PROP_RO(LuaTrainingSiteDescription, food_health),
2424 PROP_RO(LuaTrainingSiteDescription, max_attack),
2425 PROP_RO(LuaTrainingSiteDescription, max_defense),
2426 PROP_RO(LuaTrainingSiteDescription, max_evade),
2427- PROP_RO(LuaTrainingSiteDescription, max_hp),
2428+ PROP_RO(LuaTrainingSiteDescription, max_health),
2429 PROP_RO(LuaTrainingSiteDescription, max_number_of_soldiers),
2430 PROP_RO(LuaTrainingSiteDescription, min_attack),
2431 PROP_RO(LuaTrainingSiteDescription, min_defense),
2432 PROP_RO(LuaTrainingSiteDescription, min_evade),
2433- PROP_RO(LuaTrainingSiteDescription, min_hp),
2434+ PROP_RO(LuaTrainingSiteDescription, min_health),
2435 PROP_RO(LuaTrainingSiteDescription, weapons_attack),
2436 PROP_RO(LuaTrainingSiteDescription, weapons_defense),
2437 PROP_RO(LuaTrainingSiteDescription, weapons_evade),
2438- PROP_RO(LuaTrainingSiteDescription, weapons_hp),
2439+ PROP_RO(LuaTrainingSiteDescription, weapons_health),
2440 {nullptr, nullptr, nullptr},
2441 };
2442
2443@@ -2235,13 +2235,13 @@
2444
2445
2446 /* RST
2447- .. attribute:: food_hp
2448+ .. attribute:: food_health
2449
2450 (RO) A table of tables with food ware names used for Health training,
2451 e.g. {{"barbarians_bread"}, {"fish", "meat"}}
2452 */
2453-int LuaTrainingSiteDescription::get_food_hp(lua_State * L) {
2454- return food_list_to_lua(L, get()->get_food_hp());
2455+int LuaTrainingSiteDescription::get_food_health(lua_State * L) {
2456+ return food_list_to_lua(L, get()->get_food_health());
2457 }
2458
2459
2460@@ -2253,7 +2253,7 @@
2461 int LuaTrainingSiteDescription::get_max_attack(lua_State * L) {
2462 const TrainingSiteDescr* descr = get();
2463 if (descr->get_train_attack())
2464- lua_pushinteger(L, descr->get_max_level(atrAttack));
2465+ lua_pushinteger(L, descr->get_max_level(TrainingAttribute::kAttack));
2466 else
2467 lua_pushnil(L);
2468 return 1;
2469@@ -2267,7 +2267,7 @@
2470 int LuaTrainingSiteDescription::get_max_defense(lua_State * L) {
2471 const TrainingSiteDescr* descr = get();
2472 if (descr->get_train_defense())
2473- lua_pushinteger(L, descr->get_max_level(atrDefense));
2474+ lua_pushinteger(L, descr->get_max_level(TrainingAttribute::kDefense));
2475 else
2476 lua_pushnil(L);
2477 return 1;
2478@@ -2282,21 +2282,21 @@
2479 int LuaTrainingSiteDescription::get_max_evade(lua_State * L) {
2480 const TrainingSiteDescr * descr = get();
2481 if (descr->get_train_evade())
2482- lua_pushinteger(L, descr->get_max_level(atrEvade));
2483+ lua_pushinteger(L, descr->get_max_level(TrainingAttribute::kEvade));
2484 else lua_pushnil(L);
2485 return 1;
2486 }
2487
2488
2489 /* RST
2490- .. attribute:: max_hp
2491+ .. attribute:: max_health
2492
2493 (RO) The number of health points that a soldier can train
2494 */
2495-int LuaTrainingSiteDescription::get_max_hp(lua_State * L) {
2496+int LuaTrainingSiteDescription::get_max_health(lua_State * L) {
2497 const TrainingSiteDescr * descr = get();
2498- if (descr->get_train_hp())
2499- lua_pushinteger(L, descr->get_max_level(atrHP));
2500+ if (descr->get_train_health())
2501+ lua_pushinteger(L, descr->get_max_level(TrainingAttribute::kHealth));
2502 else lua_pushnil(L);
2503 return 1;
2504 }
2505@@ -2322,7 +2322,7 @@
2506 int LuaTrainingSiteDescription::get_min_attack(lua_State * L) {
2507 const TrainingSiteDescr * descr = get();
2508 if (descr->get_train_attack())
2509- lua_pushinteger(L, descr->get_min_level(atrAttack));
2510+ lua_pushinteger(L, descr->get_min_level(TrainingAttribute::kAttack));
2511 else lua_pushnil(L);
2512 return 1;
2513 }
2514@@ -2335,7 +2335,7 @@
2515 int LuaTrainingSiteDescription::get_min_defense(lua_State * L) {
2516 const TrainingSiteDescr * descr = get();
2517 if (descr->get_train_defense())
2518- lua_pushinteger(L, descr->get_min_level(atrDefense));
2519+ lua_pushinteger(L, descr->get_min_level(TrainingAttribute::kDefense));
2520 else lua_pushnil(L);
2521 return 1;
2522 }
2523@@ -2349,21 +2349,21 @@
2524 int LuaTrainingSiteDescription::get_min_evade(lua_State * L) {
2525 const TrainingSiteDescr * descr = get();
2526 if (descr->get_train_evade())
2527- lua_pushinteger(L, descr->get_min_level(atrEvade));
2528+ lua_pushinteger(L, descr->get_min_level(TrainingAttribute::kEvade));
2529 else lua_pushnil(L);
2530 return 1;
2531 }
2532
2533
2534 /* RST
2535- .. attribute:: min_hp
2536+ .. attribute:: min_health
2537
2538 (RO) The number of health points that a soldier starts training with
2539 */
2540-int LuaTrainingSiteDescription::get_min_hp(lua_State * L) {
2541+int LuaTrainingSiteDescription::get_min_health(lua_State * L) {
2542 const TrainingSiteDescr * descr = get();
2543- if (descr->get_train_hp())
2544- lua_pushinteger(L, descr->get_min_level(atrHP));
2545+ if (descr->get_train_health())
2546+ lua_pushinteger(L, descr->get_min_level(TrainingAttribute::kHealth));
2547 else lua_pushnil(L);
2548 return 1;
2549 }
2550@@ -2417,14 +2417,14 @@
2551 }
2552
2553 /* RST
2554- .. attribute:: weapons_hp
2555+ .. attribute:: weapons_health
2556
2557 (RO) A table with weapon ware names used for Health training
2558 */
2559-int LuaTrainingSiteDescription::get_weapons_hp(lua_State * L) {
2560+int LuaTrainingSiteDescription::get_weapons_health(lua_State * L) {
2561 lua_newtable(L);
2562 int counter = 0;
2563- for (const std::string& weaponname : get()->get_weapons_hp()) {
2564+ for (const std::string& weaponname : get()->get_weapons_health()) {
2565 lua_pushnumber(L, ++counter);
2566 lua_pushstring(L, weaponname);
2567 lua_settable(L, -3);
2568@@ -4764,7 +4764,7 @@
2569 const PropertyType<LuaSoldier> LuaSoldier::Properties[] = {
2570 PROP_RO(LuaSoldier, attack_level),
2571 PROP_RO(LuaSoldier, defense_level),
2572- PROP_RO(LuaSoldier, hp_level),
2573+ PROP_RO(LuaSoldier, health_level),
2574 PROP_RO(LuaSoldier, evade_level),
2575 {nullptr, nullptr, nullptr},
2576 };
2577@@ -4798,13 +4798,13 @@
2578 }
2579
2580 /* RST
2581- .. attribute:: hp_level
2582+ .. attribute:: health_level
2583
2584- (RO) The current hp level of this soldier
2585+ (RO) The current health level of this soldier
2586 */
2587 // UNTESTED
2588-int LuaSoldier::get_hp_level(lua_State * L) {
2589- lua_pushuint32(L, get(L, get_egbase(L))->get_hp_level());
2590+int LuaSoldier::get_health_level(lua_State * L) {
2591+ lua_pushuint32(L, get(L, get_egbase(L))->get_health_level());
2592 return 1;
2593 }
2594
2595
2596=== modified file 'src/scripting/lua_map.h'
2597--- src/scripting/lua_map.h 2016-02-27 08:43:39 +0000
2598+++ src/scripting/lua_map.h 2016-03-09 16:59:37 +0000
2599@@ -423,20 +423,20 @@
2600 int get_food_attack(lua_State *);
2601 int get_food_defense(lua_State *);
2602 int get_food_evade(lua_State *);
2603- int get_food_hp(lua_State *);
2604+ int get_food_health(lua_State *);
2605 int get_max_attack(lua_State *);
2606 int get_max_defense(lua_State *);
2607 int get_max_evade(lua_State *);
2608- int get_max_hp(lua_State *);
2609+ int get_max_health(lua_State *);
2610 int get_max_number_of_soldiers(lua_State *);
2611 int get_min_attack(lua_State *);
2612 int get_min_defense(lua_State *);
2613 int get_min_evade(lua_State *);
2614- int get_min_hp(lua_State *);
2615+ int get_min_health(lua_State *);
2616 int get_weapons_attack(lua_State *);
2617 int get_weapons_defense(lua_State *);
2618 int get_weapons_evade(lua_State *);
2619- int get_weapons_hp(lua_State *);
2620+ int get_weapons_health(lua_State *);
2621
2622 /*
2623 * Lua methods
2624@@ -1092,7 +1092,7 @@
2625 */
2626 int get_attack_level(lua_State *);
2627 int get_defense_level(lua_State *);
2628- int get_hp_level(lua_State *);
2629+ int get_health_level(lua_State *);
2630 int get_evade_level(lua_State *);
2631
2632 /*
2633
2634=== modified file 'src/wui/soldierlist.cc'
2635--- src/wui/soldierlist.cc 2016-02-09 08:07:48 +0000
2636+++ src/wui/soldierlist.cc 2016-03-09 16:59:37 +0000
2637@@ -41,7 +41,7 @@
2638 using Widelands::SoldierControl;
2639
2640 /**
2641- * Iconic representation of soldiers, including their levels and current HP.
2642+ * Iconic representation of soldiers, including their levels and current health.
2643 */
2644 struct SoldierPanel : UI::Panel {
2645 using SoldierFn = boost::function<void (const Soldier *)>;
2646@@ -257,9 +257,9 @@
2647 uint32_t level = soldier->get_attack_level();
2648 level = level * (soldier->descr().get_max_defense_level() + 1) + soldier->get_defense_level();
2649 level = level * (soldier->descr().get_max_evade_level() + 1) + soldier->get_evade_level();
2650- level = level * (soldier->descr().get_max_hp_level() + 1) + soldier->get_hp_level();
2651+ level = level * (soldier->descr().get_max_health_level() + 1) + soldier->get_health_level();
2652
2653- uint32_t health = soldier->get_current_hitpoints();
2654+ uint32_t health = soldier->get_current_health();
2655
2656 if (health != icon.cache_health || level != icon.cache_level) {
2657 icon.cache_level = level;
2658@@ -484,7 +484,7 @@
2659
2660 m_infotext.set_text(
2661 (boost::format(_("HP: %1$u/%2$u AT: %3$u/%4$u DE: %5$u/%6$u EV: %7$u/%8$u"))
2662- % soldier->get_hp_level() % soldier->descr().get_max_hp_level()
2663+ % soldier->get_health_level() % soldier->descr().get_max_health_level()
2664 % soldier->get_attack_level() % soldier->descr().get_max_attack_level()
2665 % soldier->get_defense_level() % soldier->descr().get_max_defense_level()
2666 % soldier->get_evade_level() % soldier->descr().get_max_evade_level()
2667
2668=== modified file 'src/wui/trainingsitewindow.cc'
2669--- src/wui/trainingsitewindow.cc 2016-01-28 05:24:34 +0000
2670+++ src/wui/trainingsitewindow.cc 2016-03-09 16:59:37 +0000
2671@@ -25,7 +25,6 @@
2672 #include "wui/soldierlist.h"
2673
2674 using Widelands::TrainingSite;
2675-using Widelands::atrAttack;
2676
2677 static char const * pic_tab_military = "images/wui/buildings/menu_tab_military.png";
2678
2679
2680=== modified file 'test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua'
2681--- test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2016-02-15 19:02:29 +0000
2682+++ test/maps/lua_testsuite.wmf/scripting/immovables_descriptions.lua 2016-03-09 16:59:37 +0000
2683@@ -386,9 +386,9 @@
2684 assert_equal(nil, egbase:get_building_description("barbarians_trainingcamp").max_evade)
2685 end
2686
2687-function test_descr:test_max_hp()
2688- assert_equal(nil, egbase:get_building_description("barbarians_battlearena").max_hp)
2689- assert_equal(2, egbase:get_building_description("barbarians_trainingcamp").max_hp)
2690+function test_descr:test_max_health()
2691+ assert_equal(nil, egbase:get_building_description("barbarians_battlearena").max_health)
2692+ assert_equal(2, egbase:get_building_description("barbarians_trainingcamp").max_health)
2693 end
2694
2695 function test_descr:test_min_attack()
2696@@ -407,9 +407,9 @@
2697 assert_equal(nil, egbase:get_building_description("barbarians_trainingcamp").min_evade)
2698 end
2699
2700-function test_descr:test_min_hp()
2701- assert_equal(nil, egbase:get_building_description("barbarians_battlearena").min_hp)
2702- assert_equal(0, egbase:get_building_description("barbarians_trainingcamp").min_hp)
2703+function test_descr:test_min_health()
2704+ assert_equal(nil, egbase:get_building_description("barbarians_battlearena").min_health)
2705+ assert_equal(0, egbase:get_building_description("barbarians_trainingcamp").min_health)
2706 end
2707
2708 function test_descr:test_type()
2709
2710=== modified file 'test/maps/lua_testsuite.wmf/scripting/warehouse.lua'
2711--- test/maps/lua_testsuite.wmf/scripting/warehouse.lua 2015-10-31 12:11:44 +0000
2712+++ test/maps/lua_testsuite.wmf/scripting/warehouse.lua 2016-03-09 16:59:37 +0000
2713@@ -168,8 +168,8 @@
2714 assert_equal(2, self.w:get_soldiers({1,1,0,1}))
2715 assert_equal(0, self.w:get_soldiers({2,1,0,1}))
2716 end
2717-function warehouse_tests:test_set_soldiers_hp_too_high()
2718- assert_error("hp too high", function()
2719+function warehouse_tests:test_set_soldiers_health_too_high()
2720+ assert_error("health too high", function()
2721 self.w:set_soldiers({10,0,0,0}, 1)
2722 end)
2723 end

Subscribers

People subscribed via source and target branches

to status/vote changes: