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

Proposed by SirVer
Status: Merged
Merged at revision: 8225
Proposed branch: lp:~widelands-dev/widelands/wood_gnome_infinite_trees
Merge into: lp:widelands
Diff against target: 26 lines (+8/-2)
1 file modified
data/scripting/win_conditions/wood_gnome.lua (+8/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/wood_gnome_infinite_trees
Reviewer Review Type Date Requested Status
TiborB Approve
GunChleoc Approve
SirVer Needs Resubmitting
Review via email: mp+313397@code.launchpad.net

Commit message

When a player is defeated, it is removed from the 'plrs' array by the 'check_player_defeated'. This lead to this players points not being reset on recalculation, ergo on each calculation the player gained the number of trees currently on its terrain as points. A classical CS bug: Cache invalidation errors.

Also: no longer calculate score for a defeated player.

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

The game crashed with:

Fatal exception: [/var/widelands/BZR/bad_cast/src/scripting/lua_errors.cc:22] [string "scripting/win_conditions/wood_gnome.lua"]:79: attempt to perform arithmetic on a nil value (field '?')

review: Needs Fixing
Revision history for this message
SirVer (sirver) wrote :

thanks for testing - I made a thinko here. Will look into it tomorrow or on the weekend.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Why do you do _plrpoints[k] = nil and not _plrpoints[k] = 0? The crashy line is probably trying to calculate nil + 1.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1771. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/184368559.
Appveyor build 1609. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_wood_gnome_infinite_trees-1609.

Revision history for this message
SirVer (sirver) wrote :

> The crashy line is probably trying to calculate nil + 1.

yes, that is what happens. I forgot that a defeated player could still own land - which opens the possibilities for a real broken situation: if you have no warehouse, the game declares you as defeated - but theoretically you could still own the most trees at 4 hours. In this case, the came would declare a defeated player as the winner. I decided that this makes no sense and now no longer count trees for defeated players.

ptal (please take another look).

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

Code LGTM, not tested.

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

('The read operation timed out',)

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1774. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/184461866.
Appveyor build 1612. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_wood_gnome_infinite_trees-1612.

Revision history for this message
TiborB (tiborb95) wrote :

Tested. Seems OK now.

review: Approve
Revision history for this message
SirVer (sirver) wrote :

@bunnybot merge

> Am 16.12.2016 um 22:37 schrieb TiborB <email address hidden>:
>
> Review: Approve
>
> Tested. Seems OK now.
> --
> https://code.launchpad.net/~widelands-dev/widelands/wood_gnome_infinite_trees/+merge/313397
> You proposed lp:~widelands-dev/widelands/wood_gnome_infinite_trees for merging.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/scripting/win_conditions/wood_gnome.lua'
2--- data/scripting/win_conditions/wood_gnome.lua 2016-09-17 11:29:34 +0000
3+++ data/scripting/win_conditions/wood_gnome.lua 2016-12-16 06:32:50 +0000
4@@ -57,14 +57,20 @@
5 return _plrpoints
6 end
7
8- -- init the playerpoints for each player
9+ -- clear out the table. We count afresh.
10+ for k,v in pairs(_plrpoints) do
11+ _plrpoints[k] = 0
12+ end
13+
14+ -- Insert all players who are still in the game.
15 for idx,plr in ipairs(plrs) do
16 _plrpoints[plr.number] = 0
17 end
18+
19 for idf,f in ipairs(fields) do
20 -- check if field is owned by a player
21 local owner = f.owner
22- if owner then
23+ if owner and not owner.defeated then
24 owner = owner.number
25 -- check if field has an immovable
26 local imm = f.immovable

Subscribers

People subscribed via source and target branches

to status/vote changes: