~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to data/maps/MP_Scenarios/Smugglers.wmf/scripting/multiplayer_init.lua

Merged lp:~widelands-dev/widelands/bug-1751440-smugglers-desync-single-coroutine:
Fixed desync in the Smugglers scenario by using a single coroutine and selecting the wares round robin. The scenario can now be played with any tribe combination as soon as we implement the selection code in the UI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
points_to_win = 2000
19
19
 
20
 
route_descrs = {
21
 
   { value = 2, send = map:get_field(35, 52):region(2), recv = map:get_field(96, 77):region(2) },
22
 
   { value = 2, send = map:get_field(98, 55):region(2), recv = map:get_field(34, 76):region(2) },
23
 
 
24
 
   { value = 3, send = map:get_field(64, 57):region(2), recv = map:get_field(78, 73):region(2) },
25
 
   { value = 3, send = map:get_field(77, 58):region(2), recv = map:get_field(65, 72):region(2) },
26
 
 
27
 
   { value = 2, send = map:get_field(62, 93):region(2), recv = map:get_field(78, 34):region(2) },
28
 
   { value = 2, send = map:get_field(80, 95):region(2), recv = map:get_field(63, 29):region(2) },
29
 
   { value = 2, send = map:get_field(18, 66):region(2), recv = map:get_field(121, 61):region(2) },
30
 
   { value = 2, send = map:get_field(124, 72):region(2), recv = map:get_field(19, 57):region(2) }
31
 
}
32
 
 
33
20
-- =================
34
21
-- Global Variables
35
22
-- =================
41
28
-- ================
42
29
-- Initializations
43
30
-- ================
 
31
 
 
32
-- If the tribes don't have any wares in common, nothing can be smuggled
 
33
-- This should not happen, but let's have a safeguard anyway.
 
34
function check_ware_compatiblity(player1, player2)
 
35
   local has_compatible_ware = false
 
36
   for idx,ware in pairs(player1.tribe.wares) do
 
37
      if player2.tribe:has_ware(ware.name) then
 
38
         has_compatible_ware = true
 
39
         break
 
40
      end
 
41
   end
 
42
   if not has_compatible_ware then
 
43
      do_game_over()
 
44
   end
 
45
end
 
46
 
44
47
function assign_teams()
45
48
   game.players[1].team = 1
46
49
   game.players[2].team = 1
47
50
   game.players[3].team = 2
48
51
   game.players[4].team = 2
 
52
   check_ware_compatiblity(game.players[1], game.players[2])
 
53
   check_ware_compatiblity(game.players[3], game.players[4])
49
54
end
50
55
 
51
56
function place_headquarters()
 
57
   include "map:scripting/starting_conditions.lua"
52
58
   for idx,player in ipairs(game.players) do
53
59
      local sf = map.player_slots[player.number].starting_field
54
 
 
55
 
      prefilled_buildings(player, { "barbarians_headquarters", sf.x, sf.y,
56
 
         wares = {
57
 
            ax = 5,
58
 
            bread_paddle = 2,
59
 
            blackwood = 32,
60
 
            cloth = 5,
61
 
            coal = 12,
62
 
            felling_ax = 4,
63
 
            fire_tongs = 2,
64
 
            fish = 6,
65
 
            fishing_rod = 2,
66
 
            gold = 4,
67
 
            grout = 12,
68
 
            hammer = 12,
69
 
            hunting_spear = 2,
70
 
            iron = 12,
71
 
            iron_ore = 5,
72
 
            kitchen_tools = 4,
73
 
            meal = 4,
74
 
            meat = 6,
75
 
            pick = 14,
76
 
            barbarians_bread = 8,
77
 
            ration = 12,
78
 
            granite = 40,
79
 
            scythe = 6,
80
 
            shovel = 4,
81
 
            snack = 3,
82
 
            thatch_reed = 24,
83
 
            log = 80,
84
 
         },
85
 
         workers = {
86
 
            barbarians_blacksmith = 2,
87
 
            barbarians_brewer = 1,
88
 
            barbarians_builder = 10,
89
 
            barbarians_carrier = 40,
90
 
            barbarians_charcoal_burner = 1,
91
 
            barbarians_gardener = 1,
92
 
            barbarians_geologist = 4,
93
 
            barbarians_lime_burner = 1,
94
 
            barbarians_lumberjack = 3,
95
 
            barbarians_miner = 4,
96
 
            barbarians_ranger = 1,
97
 
            barbarians_stonemason = 2,
98
 
            barbarians_ox = 5,
99
 
         },
100
 
         soldiers = {
101
 
            [{0,0,0,0}] = 45,
102
 
         }
103
 
      })
 
60
      local tribename = player.tribe.name
 
61
      if tribename == "barbarians" then
 
62
         set_starting_conditions_barbarians(player, sf)
 
63
      elseif tribename == "empire" then
 
64
         set_starting_conditions_empire(player, sf)
 
65
      elseif tribename == "atlanteans" then
 
66
         set_starting_conditions_atlanteans(player, sf)
 
67
      elseif tribename == "frisians" then
 
68
         set_starting_conditions_frisians(player, sf)
 
69
      else
 
70
         print("We don't have starting conditions for tribe " .. tribename)
 
71
         do_game_over()
 
72
      end
104
73
   end
105
74
end
106
75
 
137
106
   for idx,descr in ipairs(route_descrs) do
138
107
      run(wait_for_established_route, descr)
139
108
   end
 
109
 
 
110
   do_smuggling()
140
111
end
141
112
 
142
113
setup_statistics_hook()