Merge lp:~widelands-dev/widelands/bug-1380287 into lp:widelands
- bug-1380287
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 7441 | ||||
Proposed branch: | lp:~widelands-dev/widelands/bug-1380287 | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
1463 lines (+610/-173) 23 files modified
src/ai/ai_help_structs.h (+1/-1) src/ai/defaultai.cc (+4/-4) src/economy/portdock.cc (+1/-2) src/logic/game.cc (+2/-2) src/logic/game.h (+3/-2) src/logic/playercommand.cc (+10/-10) src/logic/playercommand.h (+5/-5) src/logic/ship.cc (+41/-26) src/logic/ship.h (+16/-6) src/logic/walkingdir.cc (+42/-42) src/logic/walkingdir.h (+3/-3) src/scripting/lua_game.cc (+37/-0) src/scripting/lua_game.h (+1/-0) src/scripting/lua_map.cc (+273/-9) src/scripting/lua_map.h (+10/-1) src/wui/shipwindow.cc (+8/-8) test/maps/expedition.wmf/scripting/init.lua (+15/-30) test/maps/expedition.wmf/scripting/test_ship_movement_controls.lua (+115/-0) test/maps/expedition.wmf/scripting/test_starting_and_immediately_canceling.lua (+6/-2) test/maps/expedition.wmf/scripting/test_starting_wait_a_while_cancel.lua (+2/-2) test/maps/ship_transportation.wmf/scripting/init.lua (+0/-17) test/maps/ship_transportation.wmf/scripting/test_rip_portdock_with_worker_and_ware_in_transit.lua (+3/-1) test/maps/ship_transportation.wmf/scripting/test_rip_second_port_with_worker_in_portdock.lua (+12/-0) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-1380287 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Needs Fixing | ||
GunChleoc | Approve | ||
Review via email:
|
Commit message
Description of the change
I implemented some LUA interface for ships, f.e.:
map:get_ships - to get list of player' ships on map
ships.field - to get a field where ship is located
ships.status - to get status of ship (what is it doing)
port:start_
ship.scout_
ship:build_
Please review
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
GunChleoc (gunchleoc) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
@GunChleoc - of course I was thinking about this - using text instead of integers for directions. But I failed to find good conventor string<->integer like nw=6 and so. I mean a pair of functions that would change them forth and back.
I could implement the conversion in this code, but it would broke if somebody changed the enum somewhere... But I could do this, allright... I will consider it....
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
GunChleoc (gunchleoc) wrote : | # |
Do something like this (I don't remember the exact enum variable names):
if (direction == Ship::Direction
lua_
} elseif ...
then everything will always be referenced by a name.
I have done something similar in lua_map.cc for the BuildingDescription types, in case you want to steal some code.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
This is the easier conversion, but I need also backward conversion... But it seems there is also example for this.... I will look at it once more...
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
GunChleoc (gunchleoc) wrote : | # |
I forgot that in this direction, it is better to use a switch statement. Something I learned from SirVer - the code will run faster, because it just jumps using the variable as an address instead of making a full comparison.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
reworked to use the strings
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
GunChleoc (gunchleoc) wrote : | # |
I refactored the enums, made the status function return strings, and added some tests. Please review my code before merging.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
SirVer (sirver) wrote : | # |
I found a couple more nits. Otherwise LGTM, please merge after fixing them.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
comments fixed, I rerun the regression test (all OK) and merged it to trunk
Preview Diff
1 | === modified file 'src/ai/ai_help_structs.h' | |||
2 | --- src/ai/ai_help_structs.h 2015-03-26 06:59:37 +0000 | |||
3 | +++ src/ai/ai_help_structs.h 2015-04-07 20:58:43 +0000 | |||
4 | @@ -438,7 +438,7 @@ | |||
5 | 438 | 438 | ||
6 | 439 | // a ship circumvents all islands in the same direction, the value | 439 | // a ship circumvents all islands in the same direction, the value |
7 | 440 | // is assigned only once | 440 | // is assigned only once |
9 | 441 | Widelands::ScoutingDirection island_circ_direction = Widelands::ScoutingDirection::kClockwise; | 441 | Widelands::IslandExploreDirection island_circ_direction = Widelands::IslandExploreDirection::kClockwise; |
10 | 442 | bool waiting_for_command_ = false; | 442 | bool waiting_for_command_ = false; |
11 | 443 | int32_t last_command_time = 0; | 443 | int32_t last_command_time = 0; |
12 | 444 | }; | 444 | }; |
13 | 445 | 445 | ||
14 | === modified file 'src/ai/defaultai.cc' | |||
15 | --- src/ai/defaultai.cc 2015-03-26 20:35:19 +0000 | |||
16 | +++ src/ai/defaultai.cc 2015-04-07 20:58:43 +0000 | |||
17 | @@ -3795,9 +3795,9 @@ | |||
18 | 3795 | allships.push_back(ShipObserver()); | 3795 | allships.push_back(ShipObserver()); |
19 | 3796 | allships.back().ship = &ship; | 3796 | allships.back().ship = &ship; |
20 | 3797 | if (game().get_gametime() % 2 == 0) { | 3797 | if (game().get_gametime() % 2 == 0) { |
22 | 3798 | allships.back().island_circ_direction = ScoutingDirection::kClockwise; | 3798 | allships.back().island_circ_direction = IslandExploreDirection::kClockwise; |
23 | 3799 | } else { | 3799 | } else { |
25 | 3800 | allships.back().island_circ_direction = ScoutingDirection::kCounterClockwise; | 3800 | allships.back().island_circ_direction = IslandExploreDirection::kCounterClockwise; |
26 | 3801 | } | 3801 | } |
27 | 3802 | } | 3802 | } |
28 | 3803 | 3803 | ||
29 | @@ -4058,10 +4058,10 @@ | |||
30 | 4058 | so.waiting_for_command_ = false; | 4058 | so.waiting_for_command_ = false; |
31 | 4059 | ; | 4059 | ; |
32 | 4060 | } else { | 4060 | } else { |
34 | 4061 | // 2.B Yes, pick one of avaiable directions | 4061 | // 2.B Yes, pick one of avaliable directions |
35 | 4062 | const Direction final_direction = | 4062 | const Direction final_direction = |
36 | 4063 | possible_directions.at(gametime % possible_directions.size()); | 4063 | possible_directions.at(gametime % possible_directions.size()); |
38 | 4064 | game().send_player_ship_scout_direction(*so.ship, final_direction); | 4064 | game().send_player_ship_scouting_direction(*so.ship, static_cast<WalkingDir>(final_direction)); |
39 | 4065 | so.last_command_time = gametime; | 4065 | so.last_command_time = gametime; |
40 | 4066 | so.waiting_for_command_ = false; | 4066 | so.waiting_for_command_ = false; |
41 | 4067 | } | 4067 | } |
42 | 4068 | 4068 | ||
43 | === modified file 'src/economy/portdock.cc' | |||
44 | --- src/economy/portdock.cc 2015-02-16 20:23:15 +0000 | |||
45 | +++ src/economy/portdock.cc 2015-04-07 20:58:43 +0000 | |||
46 | @@ -213,12 +213,11 @@ | |||
47 | 213 | 213 | ||
48 | 214 | PlayerImmovable::cleanup(egbase); | 214 | PlayerImmovable::cleanup(egbase); |
49 | 215 | 215 | ||
51 | 216 | //now let attempt to recreate the portdock | 216 | // Now let's attempt to recreate the portdock. |
52 | 217 | if (wh) { | 217 | if (wh) { |
53 | 218 | if (!wh->m_cleanup_in_progress){ | 218 | if (!wh->m_cleanup_in_progress){ |
54 | 219 | if (upcast(Game, game, &egbase)) { | 219 | if (upcast(Game, game, &egbase)) { |
55 | 220 | if (game->is_loaded()) { //do not attempt when shutting down | 220 | if (game->is_loaded()) { //do not attempt when shutting down |
56 | 221 | Player& player = owner(); | ||
57 | 222 | wh->restore_portdock_or_destroy(egbase); | 221 | wh->restore_portdock_or_destroy(egbase); |
58 | 223 | } | 222 | } |
59 | 224 | } | 223 | } |
60 | 225 | 224 | ||
61 | === modified file 'src/logic/game.cc' | |||
62 | --- src/logic/game.cc 2015-02-08 19:08:36 +0000 | |||
63 | +++ src/logic/game.cc 2015-04-07 20:58:43 +0000 | |||
64 | @@ -874,7 +874,7 @@ | |||
65 | 874 | } | 874 | } |
66 | 875 | 875 | ||
67 | 876 | 876 | ||
69 | 877 | void Game::send_player_ship_scout_direction(Ship & ship, uint8_t direction) | 877 | void Game::send_player_ship_scouting_direction(Ship & ship, WalkingDir direction) |
70 | 878 | { | 878 | { |
71 | 879 | send_player_command | 879 | send_player_command |
72 | 880 | (*new CmdShipScoutDirection | 880 | (*new CmdShipScoutDirection |
73 | @@ -888,7 +888,7 @@ | |||
74 | 888 | (get_gametime(), ship.get_owner()->player_number(), ship.serial(), coords)); | 888 | (get_gametime(), ship.get_owner()->player_number(), ship.serial(), coords)); |
75 | 889 | } | 889 | } |
76 | 890 | 890 | ||
78 | 891 | void Game::send_player_ship_explore_island(Ship & ship, ScoutingDirection direction) | 891 | void Game::send_player_ship_explore_island(Ship & ship, IslandExploreDirection direction) |
79 | 892 | { | 892 | { |
80 | 893 | send_player_command | 893 | send_player_command |
81 | 894 | (*new CmdShipExploreIsland | 894 | (*new CmdShipExploreIsland |
82 | 895 | 895 | ||
83 | === modified file 'src/logic/game.h' | |||
84 | --- src/logic/game.h 2015-02-08 19:08:36 +0000 | |||
85 | +++ src/logic/game.h 2015-04-07 20:58:43 +0000 | |||
86 | @@ -41,6 +41,7 @@ | |||
87 | 41 | struct Flag; | 41 | struct Flag; |
88 | 42 | struct Path; | 42 | struct Path; |
89 | 43 | struct PlayerImmovable; | 43 | struct PlayerImmovable; |
90 | 44 | enum class IslandExploreDirection; | ||
91 | 44 | enum class ScoutingDirection; | 45 | enum class ScoutingDirection; |
92 | 45 | struct Ship; | 46 | struct Ship; |
93 | 46 | struct PlayerEndStatus; | 47 | struct PlayerEndStatus; |
94 | @@ -181,9 +182,9 @@ | |||
95 | 181 | void send_player_enemyflagaction | 182 | void send_player_enemyflagaction |
96 | 182 | (const Flag &, PlayerNumber, uint32_t count); | 183 | (const Flag &, PlayerNumber, uint32_t count); |
97 | 183 | 184 | ||
99 | 184 | void send_player_ship_scout_direction(Ship &, uint8_t); | 185 | void send_player_ship_scouting_direction(Ship &, WalkingDir); |
100 | 185 | void send_player_ship_construct_port(Ship &, Coords); | 186 | void send_player_ship_construct_port(Ship &, Coords); |
102 | 186 | void send_player_ship_explore_island(Ship &, ScoutingDirection); | 187 | void send_player_ship_explore_island(Ship &, IslandExploreDirection); |
103 | 187 | void send_player_sink_ship(Ship &); | 188 | void send_player_sink_ship(Ship &); |
104 | 188 | void send_player_cancel_expedition_ship(Ship &); | 189 | void send_player_cancel_expedition_ship(Ship &); |
105 | 189 | 190 | ||
106 | 190 | 191 | ||
107 | === modified file 'src/logic/playercommand.cc' | |||
108 | --- src/logic/playercommand.cc 2015-02-19 19:37:09 +0000 | |||
109 | +++ src/logic/playercommand.cc 2015-04-07 20:58:43 +0000 | |||
110 | @@ -777,7 +777,7 @@ | |||
111 | 777 | PlayerCommand (0, des.unsigned_8()) | 777 | PlayerCommand (0, des.unsigned_8()) |
112 | 778 | { | 778 | { |
113 | 779 | serial = des.unsigned_32(); | 779 | serial = des.unsigned_32(); |
115 | 780 | dir = des.unsigned_8(); | 780 | dir = static_cast<WalkingDir>(des.unsigned_8()); |
116 | 781 | } | 781 | } |
117 | 782 | 782 | ||
118 | 783 | void CmdShipScoutDirection::execute (Game & game) | 783 | void CmdShipScoutDirection::execute (Game & game) |
119 | @@ -796,7 +796,7 @@ | |||
120 | 796 | (ship->state_is_expedition())?"Y":"N"); | 796 | (ship->state_is_expedition())?"Y":"N"); |
121 | 797 | return; | 797 | return; |
122 | 798 | } | 798 | } |
124 | 799 | ship->exp_scout_direction(game, dir); | 799 | ship->exp_scouting_direction(game, dir); |
125 | 800 | } | 800 | } |
126 | 801 | } | 801 | } |
127 | 802 | 802 | ||
128 | @@ -805,7 +805,7 @@ | |||
129 | 805 | ser.unsigned_8 (PLCMD_SHIP_SCOUT); | 805 | ser.unsigned_8 (PLCMD_SHIP_SCOUT); |
130 | 806 | ser.unsigned_8 (sender()); | 806 | ser.unsigned_8 (sender()); |
131 | 807 | ser.unsigned_32(serial); | 807 | ser.unsigned_32(serial); |
133 | 808 | ser.unsigned_8 (dir); | 808 | ser.unsigned_8 (static_cast<uint8_t>(dir)); |
134 | 809 | } | 809 | } |
135 | 810 | 810 | ||
136 | 811 | #define PLAYER_CMD_SHIP_SCOUT_DIRECTION_VERSION 1 | 811 | #define PLAYER_CMD_SHIP_SCOUT_DIRECTION_VERSION 1 |
137 | @@ -818,7 +818,7 @@ | |||
138 | 818 | PlayerCommand::read(fr, egbase, mol); | 818 | PlayerCommand::read(fr, egbase, mol); |
139 | 819 | serial = get_object_serial_or_zero<Ship>(fr.unsigned_32(), mol); | 819 | serial = get_object_serial_or_zero<Ship>(fr.unsigned_32(), mol); |
140 | 820 | // direction | 820 | // direction |
142 | 821 | dir = fr.unsigned_8(); | 821 | dir = static_cast<WalkingDir>(fr.unsigned_8()); |
143 | 822 | } else | 822 | } else |
144 | 823 | throw GameDataError("unknown/unhandled version %u", packet_version); | 823 | throw GameDataError("unknown/unhandled version %u", packet_version); |
145 | 824 | } catch (const WException & e) { | 824 | } catch (const WException & e) { |
146 | @@ -837,7 +837,7 @@ | |||
147 | 837 | fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial))); | 837 | fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial))); |
148 | 838 | 838 | ||
149 | 839 | // direction | 839 | // direction |
151 | 840 | fw.unsigned_8(dir); | 840 | fw.unsigned_8(static_cast<uint8_t>(dir)); |
152 | 841 | } | 841 | } |
153 | 842 | 842 | ||
154 | 843 | 843 | ||
155 | @@ -912,7 +912,7 @@ | |||
156 | 912 | PlayerCommand (0, des.unsigned_8()) | 912 | PlayerCommand (0, des.unsigned_8()) |
157 | 913 | { | 913 | { |
158 | 914 | serial = des.unsigned_32(); | 914 | serial = des.unsigned_32(); |
160 | 915 | scouting_direction = static_cast<ScoutingDirection>(des.unsigned_8()); | 915 | island_explore_direction = static_cast<IslandExploreDirection>(des.unsigned_8()); |
161 | 916 | } | 916 | } |
162 | 917 | 917 | ||
163 | 918 | void CmdShipExploreIsland::execute (Game & game) | 918 | void CmdShipExploreIsland::execute (Game & game) |
164 | @@ -931,7 +931,7 @@ | |||
165 | 931 | (ship->state_is_expedition())?"Y":"N"); | 931 | (ship->state_is_expedition())?"Y":"N"); |
166 | 932 | return; | 932 | return; |
167 | 933 | } | 933 | } |
169 | 934 | ship->exp_explore_island(game, scouting_direction); | 934 | ship->exp_explore_island(game, island_explore_direction); |
170 | 935 | } | 935 | } |
171 | 936 | } | 936 | } |
172 | 937 | 937 | ||
173 | @@ -940,7 +940,7 @@ | |||
174 | 940 | ser.unsigned_8 (PLCMD_SHIP_EXPLORE); | 940 | ser.unsigned_8 (PLCMD_SHIP_EXPLORE); |
175 | 941 | ser.unsigned_8 (sender()); | 941 | ser.unsigned_8 (sender()); |
176 | 942 | ser.unsigned_32(serial); | 942 | ser.unsigned_32(serial); |
178 | 943 | ser.unsigned_8 (static_cast<uint8_t>(scouting_direction)); | 943 | ser.unsigned_8 (static_cast<uint8_t>(island_explore_direction)); |
179 | 944 | } | 944 | } |
180 | 945 | 945 | ||
181 | 946 | #define PLAYER_CMD_SHIP_EXPLORE_ISLAND_VERSION 1 | 946 | #define PLAYER_CMD_SHIP_EXPLORE_ISLAND_VERSION 1 |
182 | @@ -952,7 +952,7 @@ | |||
183 | 952 | if (packet_version == PLAYER_CMD_SHIP_EXPLORE_ISLAND_VERSION) { | 952 | if (packet_version == PLAYER_CMD_SHIP_EXPLORE_ISLAND_VERSION) { |
184 | 953 | PlayerCommand::read(fr, egbase, mol); | 953 | PlayerCommand::read(fr, egbase, mol); |
185 | 954 | serial = get_object_serial_or_zero<Ship>(fr.unsigned_32(), mol); | 954 | serial = get_object_serial_or_zero<Ship>(fr.unsigned_32(), mol); |
187 | 955 | scouting_direction = static_cast<ScoutingDirection>(fr.unsigned_8()); | 955 | island_explore_direction = static_cast<IslandExploreDirection>(fr.unsigned_8()); |
188 | 956 | } else | 956 | } else |
189 | 957 | throw GameDataError("unknown/unhandled version %u", packet_version); | 957 | throw GameDataError("unknown/unhandled version %u", packet_version); |
190 | 958 | } catch (const WException & e) { | 958 | } catch (const WException & e) { |
191 | @@ -971,7 +971,7 @@ | |||
192 | 971 | fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial))); | 971 | fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial))); |
193 | 972 | 972 | ||
194 | 973 | // Direction of exploration | 973 | // Direction of exploration |
196 | 974 | fw.unsigned_8(static_cast<uint8_t>(scouting_direction)); | 974 | fw.unsigned_8(static_cast<uint8_t>(island_explore_direction)); |
197 | 975 | } | 975 | } |
198 | 976 | 976 | ||
199 | 977 | 977 | ||
200 | 978 | 978 | ||
201 | === modified file 'src/logic/playercommand.h' | |||
202 | --- src/logic/playercommand.h 2015-02-05 12:11:20 +0000 | |||
203 | +++ src/logic/playercommand.h 2015-04-07 20:58:43 +0000 | |||
204 | @@ -313,7 +313,7 @@ | |||
205 | 313 | struct CmdShipScoutDirection : public PlayerCommand { | 313 | struct CmdShipScoutDirection : public PlayerCommand { |
206 | 314 | CmdShipScoutDirection() : PlayerCommand(), serial(0) {} // For savegame loading | 314 | CmdShipScoutDirection() : PlayerCommand(), serial(0) {} // For savegame loading |
207 | 315 | CmdShipScoutDirection | 315 | CmdShipScoutDirection |
209 | 316 | (int32_t const t, PlayerNumber const p, Serial s, uint8_t direction) | 316 | (int32_t const t, PlayerNumber const p, Serial s, WalkingDir direction) |
210 | 317 | : PlayerCommand(t, p), serial(s), dir(direction) | 317 | : PlayerCommand(t, p), serial(s), dir(direction) |
211 | 318 | {} | 318 | {} |
212 | 319 | 319 | ||
213 | @@ -329,7 +329,7 @@ | |||
214 | 329 | 329 | ||
215 | 330 | private: | 330 | private: |
216 | 331 | Serial serial; | 331 | Serial serial; |
218 | 332 | uint8_t dir; | 332 | WalkingDir dir; |
219 | 333 | }; | 333 | }; |
220 | 334 | 334 | ||
221 | 335 | struct CmdShipConstructPort : public PlayerCommand { | 335 | struct CmdShipConstructPort : public PlayerCommand { |
222 | @@ -357,8 +357,8 @@ | |||
223 | 357 | struct CmdShipExploreIsland : public PlayerCommand { | 357 | struct CmdShipExploreIsland : public PlayerCommand { |
224 | 358 | CmdShipExploreIsland() : PlayerCommand(), serial(0) {} // For savegame loading | 358 | CmdShipExploreIsland() : PlayerCommand(), serial(0) {} // For savegame loading |
225 | 359 | CmdShipExploreIsland | 359 | CmdShipExploreIsland |
228 | 360 | (int32_t const t, PlayerNumber const p, Serial s, ScoutingDirection direction) | 360 | (int32_t const t, PlayerNumber const p, Serial s, IslandExploreDirection direction) |
229 | 361 | : PlayerCommand(t, p), serial(s), scouting_direction(direction) | 361 | : PlayerCommand(t, p), serial(s), island_explore_direction(direction) |
230 | 362 | {} | 362 | {} |
231 | 363 | 363 | ||
232 | 364 | void write(FileWrite &, EditorGameBase &, MapObjectSaver &) override; | 364 | void write(FileWrite &, EditorGameBase &, MapObjectSaver &) override; |
233 | @@ -373,7 +373,7 @@ | |||
234 | 373 | 373 | ||
235 | 374 | private: | 374 | private: |
236 | 375 | Serial serial; | 375 | Serial serial; |
238 | 376 | ScoutingDirection scouting_direction; | 376 | IslandExploreDirection island_explore_direction; |
239 | 377 | }; | 377 | }; |
240 | 378 | 378 | ||
241 | 379 | struct CmdShipSink : public PlayerCommand { | 379 | struct CmdShipSink : public PlayerCommand { |
242 | 380 | 380 | ||
243 | === modified file 'src/logic/ship.cc' | |||
244 | --- src/logic/ship.cc 2015-02-05 12:11:20 +0000 | |||
245 | +++ src/logic/ship.cc 2015-04-07 20:58:43 +0000 | |||
246 | @@ -550,15 +550,15 @@ | |||
247 | 550 | case EXP_SCOUTING: { | 550 | case EXP_SCOUTING: { |
248 | 551 | if (m_expedition->island_exploration) { // Exploration of the island | 551 | if (m_expedition->island_exploration) { // Exploration of the island |
249 | 552 | if (exp_close_to_coast()) { | 552 | if (exp_close_to_coast()) { |
251 | 553 | if (m_expedition->direction == 0) { | 553 | if (m_expedition->scouting_direction == WalkingDir::IDLE) { |
252 | 554 | // Make sure we know the location of the coast and use it as initial direction we | 554 | // Make sure we know the location of the coast and use it as initial direction we |
253 | 555 | // come from | 555 | // come from |
256 | 556 | m_expedition->direction = WALK_SE; | 556 | m_expedition->scouting_direction = WALK_SE; |
257 | 557 | for (uint8_t secure = 0; exp_dir_swimable(m_expedition->direction); ++secure) { | 557 | for (uint8_t secure = 0; exp_dir_swimable(m_expedition->scouting_direction); ++secure) { |
258 | 558 | assert(secure < 6); | 558 | assert(secure < 6); |
260 | 559 | m_expedition->direction = get_cw_neighbour(m_expedition->direction); | 559 | m_expedition->scouting_direction = get_cw_neighbour(m_expedition->scouting_direction); |
261 | 560 | } | 560 | } |
263 | 561 | m_expedition->direction = get_backward_dir(m_expedition->direction); | 561 | m_expedition->scouting_direction = get_backward_dir(m_expedition->scouting_direction); |
264 | 562 | // Save the position - this is where we start | 562 | // Save the position - this is where we start |
265 | 563 | m_expedition->exploration_start = get_position(); | 563 | m_expedition->exploration_start = get_position(); |
266 | 564 | } else { | 564 | } else { |
267 | @@ -579,18 +579,18 @@ | |||
268 | 579 | // The ship is supposed to follow the coast as close as possible, therefore the check | 579 | // The ship is supposed to follow the coast as close as possible, therefore the check |
269 | 580 | // for | 580 | // for |
270 | 581 | // a swimable field begins at the neighbour field of the direction we came from. | 581 | // a swimable field begins at the neighbour field of the direction we came from. |
273 | 582 | m_expedition->direction = get_backward_dir(m_expedition->direction); | 582 | m_expedition->scouting_direction = get_backward_dir(m_expedition->scouting_direction); |
274 | 583 | if (m_expedition->scouting_direction == ScoutingDirection::kClockwise) { | 583 | if (m_expedition->island_explore_direction == IslandExploreDirection::kClockwise) { |
275 | 584 | do { | 584 | do { |
278 | 585 | m_expedition->direction = get_ccw_neighbour(m_expedition->direction); | 585 | m_expedition->scouting_direction = get_ccw_neighbour(m_expedition->scouting_direction); |
279 | 586 | } while (!exp_dir_swimable(m_expedition->direction)); | 586 | } while (!exp_dir_swimable(m_expedition->scouting_direction)); |
280 | 587 | } else { | 587 | } else { |
281 | 588 | do { | 588 | do { |
284 | 589 | m_expedition->direction = get_cw_neighbour(m_expedition->direction); | 589 | m_expedition->scouting_direction = get_cw_neighbour(m_expedition->scouting_direction); |
285 | 590 | } while (!exp_dir_swimable(m_expedition->direction)); | 590 | } while (!exp_dir_swimable(m_expedition->scouting_direction)); |
286 | 591 | } | 591 | } |
287 | 592 | state.ivar1 = 1; | 592 | state.ivar1 = 1; |
289 | 593 | return start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false); | 593 | return start_task_move(game, m_expedition->scouting_direction, descr().get_sail_anims(), false); |
290 | 594 | } else { | 594 | } else { |
291 | 595 | // The ship got the command to scout around an island, but is not close to any island | 595 | // The ship got the command to scout around an island, but is not close to any island |
292 | 596 | // Most likely the command was send as the ship was on an exploration and just leaving | 596 | // Most likely the command was send as the ship was on an exploration and just leaving |
293 | @@ -615,10 +615,10 @@ | |||
294 | 615 | return start_task_idle(game, descr().main_animation(), 1500); | 615 | return start_task_idle(game, descr().main_animation(), 1500); |
295 | 616 | } | 616 | } |
296 | 617 | } else { // scouting towards a specific direction | 617 | } else { // scouting towards a specific direction |
298 | 618 | if (exp_dir_swimable(m_expedition->direction)) { | 618 | if (exp_dir_swimable(m_expedition->scouting_direction)) { |
299 | 619 | // the scouting direction is still free to move | 619 | // the scouting direction is still free to move |
300 | 620 | state.ivar1 = 1; | 620 | state.ivar1 = 1; |
302 | 621 | start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false); | 621 | start_task_move(game, m_expedition->scouting_direction, descr().get_sail_anims(), false); |
303 | 622 | return; | 622 | return; |
304 | 623 | } | 623 | } |
305 | 624 | // coast reached | 624 | // coast reached |
306 | @@ -791,9 +791,9 @@ | |||
307 | 791 | m_expedition.reset(new Expedition()); | 791 | m_expedition.reset(new Expedition()); |
308 | 792 | m_expedition->seen_port_buildspaces.reset(new std::list<Coords>()); | 792 | m_expedition->seen_port_buildspaces.reset(new std::list<Coords>()); |
309 | 793 | m_expedition->island_exploration = false; | 793 | m_expedition->island_exploration = false; |
311 | 794 | m_expedition->direction = 0; | 794 | m_expedition->scouting_direction = WalkingDir::IDLE; |
312 | 795 | m_expedition->exploration_start = Coords(0, 0); | 795 | m_expedition->exploration_start = Coords(0, 0); |
314 | 796 | m_expedition->scouting_direction = ScoutingDirection::kClockwise; | 796 | m_expedition->island_explore_direction = IslandExploreDirection::kClockwise; |
315 | 797 | m_expedition->economy.reset(new Economy(*get_owner())); | 797 | m_expedition->economy.reset(new Economy(*get_owner())); |
316 | 798 | 798 | ||
317 | 799 | // We are no longer in any other economy, but instead are an economy of our | 799 | // We are no longer in any other economy, but instead are an economy of our |
318 | @@ -824,13 +824,20 @@ | |||
319 | 824 | 824 | ||
320 | 825 | /// Initializes / changes the direction of scouting to @arg direction | 825 | /// Initializes / changes the direction of scouting to @arg direction |
321 | 826 | /// @note only called via player command | 826 | /// @note only called via player command |
323 | 827 | void Ship::exp_scout_direction(Game&, uint8_t direction) { | 827 | void Ship::exp_scouting_direction(Game&, WalkingDir scouting_direction) { |
324 | 828 | assert(m_expedition); | 828 | assert(m_expedition); |
325 | 829 | m_ship_state = EXP_SCOUTING; | 829 | m_ship_state = EXP_SCOUTING; |
327 | 830 | m_expedition->direction = direction; | 830 | m_expedition->scouting_direction = scouting_direction; |
328 | 831 | m_expedition->island_exploration = false; | 831 | m_expedition->island_exploration = false; |
329 | 832 | } | 832 | } |
330 | 833 | 833 | ||
331 | 834 | WalkingDir Ship::get_scouting_direction() { | ||
332 | 835 | if (m_expedition && m_ship_state == EXP_SCOUTING && !m_expedition->island_exploration) { | ||
333 | 836 | return m_expedition->scouting_direction; | ||
334 | 837 | } | ||
335 | 838 | return WalkingDir::IDLE; | ||
336 | 839 | } | ||
337 | 840 | |||
338 | 834 | /// Initializes the construction of a port at @arg c | 841 | /// Initializes the construction of a port at @arg c |
339 | 835 | /// @note only called via player command | 842 | /// @note only called via player command |
340 | 836 | void Ship::exp_construct_port(Game&, const Coords& c) { | 843 | void Ship::exp_construct_port(Game&, const Coords& c) { |
341 | @@ -840,16 +847,24 @@ | |||
342 | 840 | m_ship_state = EXP_COLONIZING; | 847 | m_ship_state = EXP_COLONIZING; |
343 | 841 | } | 848 | } |
344 | 842 | 849 | ||
346 | 843 | /// Initializes / changes the direction the island exploration in @arg scouting_direction direction | 850 | /// Initializes / changes the direction the island exploration in @arg island_explore_direction direction |
347 | 844 | /// @note only called via player command | 851 | /// @note only called via player command |
349 | 845 | void Ship::exp_explore_island(Game&, ScoutingDirection scouting_direction) { | 852 | void Ship::exp_explore_island(Game&, IslandExploreDirection island_explore_direction) { |
350 | 846 | assert(m_expedition); | 853 | assert(m_expedition); |
351 | 847 | m_ship_state = EXP_SCOUTING; | 854 | m_ship_state = EXP_SCOUTING; |
354 | 848 | m_expedition->scouting_direction = scouting_direction; | 855 | m_expedition->island_explore_direction = island_explore_direction; |
355 | 849 | m_expedition->direction = 0; | 856 | m_expedition->scouting_direction = WalkingDir::IDLE; |
356 | 850 | m_expedition->island_exploration = true; | 857 | m_expedition->island_exploration = true; |
357 | 851 | } | 858 | } |
358 | 852 | 859 | ||
359 | 860 | IslandExploreDirection Ship::get_island_explore_direction() { | ||
360 | 861 | if (m_expedition && m_ship_state == EXP_SCOUTING && m_expedition->island_exploration) { | ||
361 | 862 | return m_expedition->island_explore_direction; | ||
362 | 863 | } | ||
363 | 864 | return IslandExploreDirection::kNotSet; | ||
364 | 865 | } | ||
365 | 866 | |||
366 | 867 | |||
367 | 853 | /// Cancels a currently running expedition | 868 | /// Cancels a currently running expedition |
368 | 854 | /// @note only called via player command | 869 | /// @note only called via player command |
369 | 855 | void Ship::exp_cancel(Game& game) { | 870 | void Ship::exp_cancel(Game& game) { |
370 | @@ -995,11 +1010,11 @@ | |||
371 | 995 | // whether scouting or exploring | 1010 | // whether scouting or exploring |
372 | 996 | m_expedition->island_exploration = fr.unsigned_8() == 1; | 1011 | m_expedition->island_exploration = fr.unsigned_8() == 1; |
373 | 997 | // current direction | 1012 | // current direction |
375 | 998 | m_expedition->direction = fr.unsigned_8(); | 1013 | m_expedition->scouting_direction = static_cast<WalkingDir>(fr.unsigned_8()); |
376 | 999 | // Start coordinates of an island exploration | 1014 | // Start coordinates of an island exploration |
377 | 1000 | m_expedition->exploration_start = read_coords_32(&fr); | 1015 | m_expedition->exploration_start = read_coords_32(&fr); |
378 | 1001 | // Whether the exploration is done clockwise or counter clockwise | 1016 | // Whether the exploration is done clockwise or counter clockwise |
380 | 1002 | m_expedition->scouting_direction = static_cast<ScoutingDirection>(fr.unsigned_8()); | 1017 | m_expedition->island_explore_direction = static_cast<IslandExploreDirection>(fr.unsigned_8()); |
381 | 1003 | } | 1018 | } |
382 | 1004 | } else | 1019 | } else |
383 | 1005 | m_ship_state = TRANSPORT; | 1020 | m_ship_state = TRANSPORT; |
384 | @@ -1114,11 +1129,11 @@ | |||
385 | 1114 | // whether scouting or exploring | 1129 | // whether scouting or exploring |
386 | 1115 | fw.unsigned_8(m_expedition->island_exploration ? 1 : 0); | 1130 | fw.unsigned_8(m_expedition->island_exploration ? 1 : 0); |
387 | 1116 | // current direction | 1131 | // current direction |
389 | 1117 | fw.unsigned_8(m_expedition->direction); | 1132 | fw.unsigned_8(static_cast<uint8_t>(m_expedition->scouting_direction)); |
390 | 1118 | // Start coordinates of an island exploration | 1133 | // Start coordinates of an island exploration |
391 | 1119 | write_coords_32(&fw, m_expedition->exploration_start); | 1134 | write_coords_32(&fw, m_expedition->exploration_start); |
392 | 1120 | // Whether the exploration is done clockwise or counter clockwise | 1135 | // Whether the exploration is done clockwise or counter clockwise |
394 | 1121 | fw.unsigned_8(static_cast<uint8_t>(m_expedition->scouting_direction)); | 1136 | fw.unsigned_8(static_cast<uint8_t>(m_expedition->island_explore_direction)); |
395 | 1122 | } | 1137 | } |
396 | 1123 | 1138 | ||
397 | 1124 | fw.unsigned_32(mos.get_object_file_index_or_zero(m_lastdock.get(egbase))); | 1139 | fw.unsigned_32(mos.get_object_file_index_or_zero(m_lastdock.get(egbase))); |
398 | 1125 | 1140 | ||
399 | === modified file 'src/logic/ship.h' | |||
400 | --- src/logic/ship.h 2015-02-05 12:11:20 +0000 | |||
401 | +++ src/logic/ship.h 2015-04-07 20:58:43 +0000 | |||
402 | @@ -38,9 +38,10 @@ | |||
403 | 38 | class PortDock; | 38 | class PortDock; |
404 | 39 | 39 | ||
405 | 40 | // This can't be part of the Ship class because of forward declaration in game.h | 40 | // This can't be part of the Ship class because of forward declaration in game.h |
407 | 41 | enum class ScoutingDirection { | 41 | enum class IslandExploreDirection { |
408 | 42 | kCounterClockwise = 0, // This comes first for savegame compatibility (used to be = 0) | 42 | kCounterClockwise = 0, // This comes first for savegame compatibility (used to be = 0) |
410 | 43 | kClockwise = 1 | 43 | kClockwise = 1, |
411 | 44 | kNotSet | ||
412 | 44 | }; | 45 | }; |
413 | 45 | 46 | ||
414 | 46 | struct NoteShipMessage { | 47 | struct NoteShipMessage { |
415 | @@ -202,9 +203,18 @@ | |||
416 | 202 | return m_expedition->seen_port_buildspaces.get(); | 203 | return m_expedition->seen_port_buildspaces.get(); |
417 | 203 | } | 204 | } |
418 | 204 | 205 | ||
420 | 205 | void exp_scout_direction(Game &, uint8_t); | 206 | void exp_scouting_direction(Game &, WalkingDir); |
421 | 206 | void exp_construct_port (Game &, const Coords&); | 207 | void exp_construct_port (Game &, const Coords&); |
423 | 207 | void exp_explore_island (Game &, ScoutingDirection); | 208 | void exp_explore_island (Game &, IslandExploreDirection); |
424 | 209 | |||
425 | 210 | //Returns integer of direction, or WalkingDir::IDLE if query invalid | ||
426 | 211 | //Intended for LUA scripting | ||
427 | 212 | WalkingDir get_scouting_direction(); | ||
428 | 213 | |||
429 | 214 | //Returns integer of direction, or IslandExploreDirection::kNotSet | ||
430 | 215 | //if query invalid | ||
431 | 216 | //Intended for LUA scripting | ||
432 | 217 | IslandExploreDirection get_island_explore_direction(); | ||
433 | 208 | 218 | ||
434 | 209 | void exp_cancel (Game &); | 219 | void exp_cancel (Game &); |
435 | 210 | void sink_ship (Game &); | 220 | void sink_ship (Game &); |
436 | @@ -242,9 +252,9 @@ | |||
437 | 242 | std::unique_ptr<std::list<Coords> > seen_port_buildspaces; | 252 | std::unique_ptr<std::list<Coords> > seen_port_buildspaces; |
438 | 243 | bool swimable[LAST_DIRECTION]; | 253 | bool swimable[LAST_DIRECTION]; |
439 | 244 | bool island_exploration; | 254 | bool island_exploration; |
441 | 245 | uint8_t direction; | 255 | WalkingDir scouting_direction; |
442 | 246 | Coords exploration_start; | 256 | Coords exploration_start; |
444 | 247 | ScoutingDirection scouting_direction; | 257 | IslandExploreDirection island_explore_direction; |
445 | 248 | std::unique_ptr<Economy> economy; | 258 | std::unique_ptr<Economy> economy; |
446 | 249 | }; | 259 | }; |
447 | 250 | std::unique_ptr<Expedition> m_expedition; | 260 | std::unique_ptr<Expedition> m_expedition; |
448 | 251 | 261 | ||
449 | === modified file 'src/logic/walkingdir.cc' | |||
450 | --- src/logic/walkingdir.cc 2014-07-14 10:45:44 +0000 | |||
451 | +++ src/logic/walkingdir.cc 2015-04-07 20:58:43 +0000 | |||
452 | @@ -22,61 +22,61 @@ | |||
453 | 22 | namespace Widelands { | 22 | namespace Widelands { |
454 | 23 | 23 | ||
455 | 24 | /// \returns the neighbour direction in clockwise | 24 | /// \returns the neighbour direction in clockwise |
457 | 25 | uint8_t get_cw_neighbour(uint8_t dir) { | 25 | WalkingDir get_cw_neighbour(WalkingDir dir) { |
458 | 26 | switch (dir) { | 26 | switch (dir) { |
471 | 27 | case WALK_NE: | 27 | case WalkingDir::WALK_NE: |
472 | 28 | return WALK_E; | 28 | return WalkingDir::WALK_E; |
473 | 29 | case WALK_E: | 29 | case WalkingDir::WALK_E: |
474 | 30 | return WALK_SE; | 30 | return WalkingDir::WALK_SE; |
475 | 31 | case WALK_SE: | 31 | case WalkingDir::WALK_SE: |
476 | 32 | return WALK_SW; | 32 | return WalkingDir::WALK_SW; |
477 | 33 | case WALK_SW: | 33 | case WalkingDir::WALK_SW: |
478 | 34 | return WALK_W; | 34 | return WalkingDir::WALK_W; |
479 | 35 | case WALK_W: | 35 | case WalkingDir::WALK_W: |
480 | 36 | return WALK_NW; | 36 | return WalkingDir::WALK_NW; |
481 | 37 | case WALK_NW: | 37 | case WalkingDir::WALK_NW: |
482 | 38 | return WALK_NE; | 38 | return WalkingDir::WALK_NE; |
483 | 39 | default: | 39 | default: |
485 | 40 | return 0; | 40 | return WalkingDir::IDLE; |
486 | 41 | } | 41 | } |
487 | 42 | } | 42 | } |
488 | 43 | 43 | ||
489 | 44 | /// \returns the neighbour direction in counterclockwise | 44 | /// \returns the neighbour direction in counterclockwise |
491 | 45 | uint8_t get_ccw_neighbour(uint8_t dir) { | 45 | WalkingDir get_ccw_neighbour(WalkingDir dir) { |
492 | 46 | switch (dir) { | 46 | switch (dir) { |
505 | 47 | case WALK_E: | 47 | case WalkingDir::WALK_E: |
506 | 48 | return WALK_NE; | 48 | return WalkingDir::WALK_NE; |
507 | 49 | case WALK_NE: | 49 | case WalkingDir::WALK_NE: |
508 | 50 | return WALK_NW; | 50 | return WalkingDir::WALK_NW; |
509 | 51 | case WALK_NW: | 51 | case WalkingDir::WALK_NW: |
510 | 52 | return WALK_W; | 52 | return WalkingDir::WALK_W; |
511 | 53 | case WALK_W: | 53 | case WalkingDir::WALK_W: |
512 | 54 | return WALK_SW; | 54 | return WalkingDir::WALK_SW; |
513 | 55 | case WALK_SW: | 55 | case WalkingDir::WALK_SW: |
514 | 56 | return WALK_SE; | 56 | return WalkingDir::WALK_SE; |
515 | 57 | case WALK_SE: | 57 | case WalkingDir::WALK_SE: |
516 | 58 | return WALK_E; | 58 | return WalkingDir::WALK_E; |
517 | 59 | default: | 59 | default: |
519 | 60 | return 0; | 60 | return WalkingDir::IDLE; |
520 | 61 | } | 61 | } |
521 | 62 | } | 62 | } |
522 | 63 | 63 | ||
524 | 64 | uint8_t get_backward_dir(uint8_t dir) { | 64 | WalkingDir get_backward_dir(WalkingDir dir) { |
525 | 65 | switch (dir) { | 65 | switch (dir) { |
538 | 66 | case WALK_E: | 66 | case WalkingDir::WALK_E: |
539 | 67 | return WALK_W; | 67 | return WalkingDir::WALK_W; |
540 | 68 | case WALK_NE: | 68 | case WalkingDir::WALK_NE: |
541 | 69 | return WALK_SW; | 69 | return WalkingDir::WALK_SW; |
542 | 70 | case WALK_NW: | 70 | case WalkingDir::WALK_NW: |
543 | 71 | return WALK_SE; | 71 | return WalkingDir::WALK_SE; |
544 | 72 | case WALK_W: | 72 | case WalkingDir::WALK_W: |
545 | 73 | return WALK_E; | 73 | return WalkingDir::WALK_E; |
546 | 74 | case WALK_SW: | 74 | case WalkingDir::WALK_SW: |
547 | 75 | return WALK_NE; | 75 | return WalkingDir::WALK_NE; |
548 | 76 | case WALK_SE: | 76 | case WalkingDir::WALK_SE: |
549 | 77 | return WALK_NW; | 77 | return WalkingDir::WALK_NW; |
550 | 78 | default: | 78 | default: |
552 | 79 | return 0; | 79 | return WalkingDir::IDLE; |
553 | 80 | } | 80 | } |
554 | 81 | } | 81 | } |
555 | 82 | 82 | ||
556 | 83 | 83 | ||
557 | === modified file 'src/logic/walkingdir.h' | |||
558 | --- src/logic/walkingdir.h 2014-07-05 16:41:51 +0000 | |||
559 | +++ src/logic/walkingdir.h 2015-04-07 20:58:43 +0000 | |||
560 | @@ -37,9 +37,9 @@ | |||
561 | 37 | LAST_DIRECTION = 6, | 37 | LAST_DIRECTION = 6, |
562 | 38 | }; | 38 | }; |
563 | 39 | 39 | ||
567 | 40 | uint8_t get_cw_neighbour(uint8_t dir); | 40 | WalkingDir get_cw_neighbour(WalkingDir dir); |
568 | 41 | uint8_t get_ccw_neighbour(uint8_t dir); | 41 | WalkingDir get_ccw_neighbour(WalkingDir dir); |
569 | 42 | uint8_t get_backward_dir(uint8_t dir); | 42 | WalkingDir get_backward_dir(WalkingDir dir); |
570 | 43 | 43 | ||
571 | 44 | } | 44 | } |
572 | 45 | 45 | ||
573 | 46 | 46 | ||
574 | === modified file 'src/scripting/lua_game.cc' | |||
575 | --- src/scripting/lua_game.cc 2015-01-31 16:03:59 +0000 | |||
576 | +++ src/scripting/lua_game.cc 2015-04-07 20:58:43 +0000 | |||
577 | @@ -97,6 +97,7 @@ | |||
578 | 97 | METHOD(LuaPlayer, hide_fields), | 97 | METHOD(LuaPlayer, hide_fields), |
579 | 98 | METHOD(LuaPlayer, reveal_scenario), | 98 | METHOD(LuaPlayer, reveal_scenario), |
580 | 99 | METHOD(LuaPlayer, reveal_campaign), | 99 | METHOD(LuaPlayer, reveal_campaign), |
581 | 100 | METHOD(LuaPlayer, get_ships), | ||
582 | 100 | METHOD(LuaPlayer, get_buildings), | 101 | METHOD(LuaPlayer, get_buildings), |
583 | 101 | METHOD(LuaPlayer, get_suitability), | 102 | METHOD(LuaPlayer, get_suitability), |
584 | 102 | METHOD(LuaPlayer, allow_workers), | 103 | METHOD(LuaPlayer, allow_workers), |
585 | @@ -628,6 +629,7 @@ | |||
586 | 628 | int LuaPlayer::reveal_campaign(lua_State * L) { | 629 | int LuaPlayer::reveal_campaign(lua_State * L) { |
587 | 629 | if (get_game(L).get_ipl()->player_number() != player_number()) | 630 | if (get_game(L).get_ipl()->player_number() != player_number()) |
588 | 630 | report_error(L, "Can only be called for interactive player!"); | 631 | report_error(L, "Can only be called for interactive player!"); |
589 | 632 | report_error(L, "Can only be called for interactive player!"); | ||
590 | 631 | 633 | ||
591 | 632 | CampaignVisibilitySave cvs; | 634 | CampaignVisibilitySave cvs; |
592 | 633 | cvs.set_campaign_visibility(luaL_checkstring(L, 2), true); | 635 | cvs.set_campaign_visibility(luaL_checkstring(L, 2), true); |
593 | @@ -635,6 +637,41 @@ | |||
594 | 635 | return 0; | 637 | return 0; |
595 | 636 | } | 638 | } |
596 | 637 | 639 | ||
597 | 640 | /* RST | ||
598 | 641 | .. method:: get_ships() | ||
599 | 642 | |||
600 | 643 | :returns: array of player's ships | ||
601 | 644 | :rtype: :class:`array` or :class:`table` | ||
602 | 645 | */ | ||
603 | 646 | int LuaPlayer::get_ships(lua_State * L) { | ||
604 | 647 | EditorGameBase & egbase = get_egbase(L); | ||
605 | 648 | Map * map = egbase.get_map(); | ||
606 | 649 | PlayerNumber p = (get(L, egbase)).player_number(); | ||
607 | 650 | lua_newtable(L); | ||
608 | 651 | uint32_t cidx = 1; | ||
609 | 652 | |||
610 | 653 | std::set<OPtr<Ship>> found_ships; | ||
611 | 654 | for (int16_t y = 0; y < map->get_height(); ++y) { | ||
612 | 655 | for (int16_t x = 0; x < map->get_width(); ++x) { | ||
613 | 656 | FCoords f = map->get_fcoords(Coords(x, y)); | ||
614 | 657 | // there are too many bobs on the map so we investigate | ||
615 | 658 | // only bobs on water | ||
616 | 659 | if (f.field->nodecaps() & MOVECAPS_SWIM) { | ||
617 | 660 | for (Bob* bob = f.field->get_first_bob(); bob; bob = bob->get_next_on_field()) { | ||
618 | 661 | if (upcast(Ship, ship, bob)) { | ||
619 | 662 | if (ship->get_owner()->player_number() == p && !found_ships.count(ship)) { | ||
620 | 663 | found_ships.insert(ship); | ||
621 | 664 | lua_pushuint32(L, cidx++); | ||
622 | 665 | LuaMaps::upcasted_map_object_to_lua(L, ship); | ||
623 | 666 | lua_rawset(L, -3); | ||
624 | 667 | } | ||
625 | 668 | } | ||
626 | 669 | } | ||
627 | 670 | } | ||
628 | 671 | } | ||
629 | 672 | } | ||
630 | 673 | return 1; | ||
631 | 674 | } | ||
632 | 638 | 675 | ||
633 | 639 | /* RST | 676 | /* RST |
634 | 640 | .. method:: get_buildings(which) | 677 | .. method:: get_buildings(which) |
635 | 641 | 678 | ||
636 | === modified file 'src/scripting/lua_game.h' | |||
637 | --- src/scripting/lua_game.h 2015-02-09 05:57:08 +0000 | |||
638 | +++ src/scripting/lua_game.h 2015-04-07 20:58:43 +0000 | |||
639 | @@ -83,6 +83,7 @@ | |||
640 | 83 | int hide_fields(lua_State * L); | 83 | int hide_fields(lua_State * L); |
641 | 84 | int reveal_scenario(lua_State * L); | 84 | int reveal_scenario(lua_State * L); |
642 | 85 | int reveal_campaign(lua_State * L); | 85 | int reveal_campaign(lua_State * L); |
643 | 86 | int get_ships(lua_State * L); | ||
644 | 86 | int get_buildings(lua_State * L); | 87 | int get_buildings(lua_State * L); |
645 | 87 | int get_suitability(lua_State * L); | 88 | int get_suitability(lua_State * L); |
646 | 88 | int allow_workers(lua_State * L); | 89 | int allow_workers(lua_State * L); |
647 | 89 | 90 | ||
648 | === modified file 'src/scripting/lua_map.cc' | |||
649 | --- src/scripting/lua_map.cc 2015-02-12 21:03:20 +0000 | |||
650 | +++ src/scripting/lua_map.cc 2015-04-07 20:58:43 +0000 | |||
651 | @@ -32,6 +32,7 @@ | |||
652 | 32 | #include "logic/maphollowregion.h" | 32 | #include "logic/maphollowregion.h" |
653 | 33 | #include "logic/mapregion.h" | 33 | #include "logic/mapregion.h" |
654 | 34 | #include "logic/player.h" | 34 | #include "logic/player.h" |
655 | 35 | #include "logic/ship.h" | ||
656 | 35 | #include "logic/soldier.h" | 36 | #include "logic/soldier.h" |
657 | 36 | #include "logic/warelist.h" | 37 | #include "logic/warelist.h" |
658 | 37 | #include "logic/widelands_geometry.h" | 38 | #include "logic/widelands_geometry.h" |
659 | @@ -2681,13 +2682,13 @@ | |||
660 | 2681 | ========================================================== | 2682 | ========================================================== |
661 | 2682 | */ | 2683 | */ |
662 | 2683 | 2684 | ||
663 | 2685 | |||
664 | 2684 | /* | 2686 | /* |
665 | 2685 | ========================================================== | 2687 | ========================================================== |
666 | 2686 | C METHODS | 2688 | C METHODS |
667 | 2687 | ========================================================== | 2689 | ========================================================== |
668 | 2688 | */ | 2690 | */ |
669 | 2689 | 2691 | ||
670 | 2690 | |||
671 | 2691 | /* RST | 2692 | /* RST |
672 | 2692 | Building | 2693 | Building |
673 | 2693 | -------- | 2694 | -------- |
674 | @@ -2806,10 +2807,13 @@ | |||
675 | 2806 | METHOD(LuaWarehouse, get_workers), | 2807 | METHOD(LuaWarehouse, get_workers), |
676 | 2807 | METHOD(LuaWarehouse, set_soldiers), | 2808 | METHOD(LuaWarehouse, set_soldiers), |
677 | 2808 | METHOD(LuaWarehouse, get_soldiers), | 2809 | METHOD(LuaWarehouse, get_soldiers), |
678 | 2810 | METHOD(LuaWarehouse, start_expedition), | ||
679 | 2811 | METHOD(LuaWarehouse, cancel_expedition), | ||
680 | 2809 | {nullptr, nullptr}, | 2812 | {nullptr, nullptr}, |
681 | 2810 | }; | 2813 | }; |
682 | 2811 | const PropertyType<LuaWarehouse> LuaWarehouse::Properties[] = { | 2814 | const PropertyType<LuaWarehouse> LuaWarehouse::Properties[] = { |
683 | 2812 | PROP_RO(LuaWarehouse, portdock), | 2815 | PROP_RO(LuaWarehouse, portdock), |
684 | 2816 | PROP_RO(LuaWarehouse, expedition_in_progress), | ||
685 | 2813 | {nullptr, nullptr, nullptr}, | 2817 | {nullptr, nullptr, nullptr}, |
686 | 2814 | }; | 2818 | }; |
687 | 2815 | 2819 | ||
688 | @@ -2829,6 +2833,26 @@ | |||
689 | 2829 | return upcasted_map_object_to_lua(L, get(L, get_egbase(L))->get_portdock()); | 2833 | return upcasted_map_object_to_lua(L, get(L, get_egbase(L))->get_portdock()); |
690 | 2830 | } | 2834 | } |
691 | 2831 | 2835 | ||
692 | 2836 | /* RST | ||
693 | 2837 | .. attribute:: expedition_in_progress | ||
694 | 2838 | |||
695 | 2839 | (RO) If this Warehouse is a port, and an expedition is in | ||
696 | 2840 | progress, returns true, otherwise nil | ||
697 | 2841 | */ | ||
698 | 2842 | int LuaWarehouse::get_expedition_in_progress(lua_State * L) { | ||
699 | 2843 | |||
700 | 2844 | Warehouse* wh = get(L, get_egbase(L)); | ||
701 | 2845 | |||
702 | 2846 | if (upcast(Game, game, &get_egbase(L))) { | ||
703 | 2847 | PortDock* pd = wh->get_portdock(); | ||
704 | 2848 | if (pd) { | ||
705 | 2849 | if (pd->expedition_started()){ | ||
706 | 2850 | return 1; | ||
707 | 2851 | } | ||
708 | 2852 | } | ||
709 | 2853 | } | ||
710 | 2854 | return 0; | ||
711 | 2855 | } | ||
712 | 2832 | 2856 | ||
713 | 2833 | /* | 2857 | /* |
714 | 2834 | ========================================================== | 2858 | ========================================================== |
715 | @@ -2895,13 +2919,72 @@ | |||
716 | 2895 | return do_set_soldiers(L, wh->get_position(), wh, wh->get_owner()); | 2919 | return do_set_soldiers(L, wh->get_position(), wh, wh->get_owner()); |
717 | 2896 | } | 2920 | } |
718 | 2897 | 2921 | ||
719 | 2922 | /* RST | ||
720 | 2923 | .. method:: start_expedition(port) | ||
721 | 2924 | |||
722 | 2925 | :arg port | ||
723 | 2926 | |||
724 | 2927 | Starts preparation for expedition | ||
725 | 2928 | |||
726 | 2929 | */ | ||
727 | 2930 | int LuaWarehouse::start_expedition(lua_State* L) { | ||
728 | 2931 | |||
729 | 2932 | Warehouse* Wh = get(L, get_egbase(L)); | ||
730 | 2933 | |||
731 | 2934 | if (!Wh) { | ||
732 | 2935 | return 0; | ||
733 | 2936 | } | ||
734 | 2937 | |||
735 | 2938 | if (upcast(Game, game, &get_egbase(L))) { | ||
736 | 2939 | PortDock* pd = Wh->get_portdock(); | ||
737 | 2940 | if (!pd) { | ||
738 | 2941 | return 0; | ||
739 | 2942 | } | ||
740 | 2943 | if (!pd->expedition_started()){ | ||
741 | 2944 | game->send_player_start_or_cancel_expedition(*Wh); | ||
742 | 2945 | return 1; | ||
743 | 2946 | } | ||
744 | 2947 | } | ||
745 | 2948 | |||
746 | 2949 | return 0; | ||
747 | 2950 | } | ||
748 | 2951 | |||
749 | 2952 | /* RST | ||
750 | 2953 | .. method:: cancel_expedition(port) | ||
751 | 2954 | |||
752 | 2955 | :arg port | ||
753 | 2956 | |||
754 | 2957 | Cancels an expedition if in progress | ||
755 | 2958 | |||
756 | 2959 | */ | ||
757 | 2960 | int LuaWarehouse::cancel_expedition(lua_State* L) { | ||
758 | 2961 | |||
759 | 2962 | Warehouse* Wh = get(L, get_egbase(L)); | ||
760 | 2963 | |||
761 | 2964 | if (!Wh) { | ||
762 | 2965 | return 0; | ||
763 | 2966 | } | ||
764 | 2967 | |||
765 | 2968 | if (upcast(Game, game, &get_egbase(L))) { | ||
766 | 2969 | PortDock* pd = Wh->get_portdock(); | ||
767 | 2970 | if (!pd) { | ||
768 | 2971 | return 0; | ||
769 | 2972 | } | ||
770 | 2973 | if (pd->expedition_started()){ | ||
771 | 2974 | game->send_player_start_or_cancel_expedition(*Wh); | ||
772 | 2975 | return 1; | ||
773 | 2976 | } | ||
774 | 2977 | } | ||
775 | 2978 | |||
776 | 2979 | return 0; | ||
777 | 2980 | } | ||
778 | 2981 | |||
779 | 2898 | /* | 2982 | /* |
780 | 2899 | ========================================================== | 2983 | ========================================================== |
781 | 2900 | C METHODS | 2984 | C METHODS |
782 | 2901 | ========================================================== | 2985 | ========================================================== |
783 | 2902 | */ | 2986 | */ |
784 | 2903 | 2987 | ||
785 | 2904 | |||
786 | 2905 | /* RST | 2988 | /* RST |
787 | 2906 | ProductionSite | 2989 | ProductionSite |
788 | 2907 | -------------- | 2990 | -------------- |
789 | @@ -3179,6 +3262,7 @@ | |||
790 | 3179 | {nullptr, nullptr}, | 3262 | {nullptr, nullptr}, |
791 | 3180 | }; | 3263 | }; |
792 | 3181 | const PropertyType<LuaBob> LuaBob::Properties[] = { | 3264 | const PropertyType<LuaBob> LuaBob::Properties[] = { |
793 | 3265 | PROP_RO(LuaBob, field), | ||
794 | 3182 | {nullptr, nullptr, nullptr}, | 3266 | {nullptr, nullptr, nullptr}, |
795 | 3183 | }; | 3267 | }; |
796 | 3184 | 3268 | ||
797 | @@ -3189,6 +3273,27 @@ | |||
798 | 3189 | */ | 3273 | */ |
799 | 3190 | 3274 | ||
800 | 3191 | /* RST | 3275 | /* RST |
801 | 3276 | .. attribute:: field //working here | ||
802 | 3277 | |||
803 | 3278 | (RO) The field the bob is located on | ||
804 | 3279 | */ | ||
805 | 3280 | // UNTESTED | ||
806 | 3281 | int LuaBob::get_field(lua_State * L) { | ||
807 | 3282 | |||
808 | 3283 | EditorGameBase & egbase = get_egbase(L); | ||
809 | 3284 | |||
810 | 3285 | Coords coords = get(L, egbase)->get_position(); | ||
811 | 3286 | |||
812 | 3287 | return to_lua<LuaMaps::LuaField>(L, new LuaMaps::LuaField(coords.x, coords.y)); | ||
813 | 3288 | } | ||
814 | 3289 | |||
815 | 3290 | |||
816 | 3291 | /* | ||
817 | 3292 | ========================================================== | ||
818 | 3293 | LUA METHODS | ||
819 | 3294 | ========================================================== | ||
820 | 3295 | */ | ||
821 | 3296 | /* RST | ||
822 | 3192 | .. method:: has_caps(capname) | 3297 | .. method:: has_caps(capname) |
823 | 3193 | 3298 | ||
824 | 3194 | Similar to :meth:`Field::has_caps`. | 3299 | Similar to :meth:`Field::has_caps`. |
825 | @@ -3214,13 +3319,6 @@ | |||
826 | 3214 | return 1; | 3319 | return 1; |
827 | 3215 | } | 3320 | } |
828 | 3216 | 3321 | ||
829 | 3217 | |||
830 | 3218 | /* | ||
831 | 3219 | ========================================================== | ||
832 | 3220 | LUA METHODS | ||
833 | 3221 | ========================================================== | ||
834 | 3222 | */ | ||
835 | 3223 | |||
836 | 3224 | /* | 3322 | /* |
837 | 3225 | ========================================================== | 3323 | ========================================================== |
838 | 3226 | C METHODS | 3324 | C METHODS |
839 | @@ -3240,12 +3338,16 @@ | |||
840 | 3240 | const MethodType<LuaShip> LuaShip::Methods[] = { | 3338 | const MethodType<LuaShip> LuaShip::Methods[] = { |
841 | 3241 | METHOD(LuaShip, get_wares), | 3339 | METHOD(LuaShip, get_wares), |
842 | 3242 | METHOD(LuaShip, get_workers), | 3340 | METHOD(LuaShip, get_workers), |
843 | 3341 | METHOD(LuaShip, build_colonization_port), | ||
844 | 3243 | {nullptr, nullptr}, | 3342 | {nullptr, nullptr}, |
845 | 3244 | }; | 3343 | }; |
846 | 3245 | const PropertyType<LuaShip> LuaShip::Properties[] = { | 3344 | const PropertyType<LuaShip> LuaShip::Properties[] = { |
847 | 3246 | PROP_RO(LuaShip, debug_economy), | 3345 | PROP_RO(LuaShip, debug_economy), |
848 | 3247 | PROP_RO(LuaShip, last_portdock), | 3346 | PROP_RO(LuaShip, last_portdock), |
849 | 3248 | PROP_RO(LuaShip, destination), | 3347 | PROP_RO(LuaShip, destination), |
850 | 3348 | PROP_RO(LuaShip, state), | ||
851 | 3349 | PROP_RW(LuaShip, scouting_direction), | ||
852 | 3350 | PROP_RW(LuaShip, island_explore_direction), | ||
853 | 3249 | {nullptr, nullptr, nullptr}, | 3351 | {nullptr, nullptr, nullptr}, |
854 | 3250 | }; | 3352 | }; |
855 | 3251 | 3353 | ||
856 | @@ -3285,6 +3387,149 @@ | |||
857 | 3285 | return upcasted_map_object_to_lua(L, get(L, egbase)->get_lastdock(egbase)); | 3387 | return upcasted_map_object_to_lua(L, get(L, egbase)->get_lastdock(egbase)); |
858 | 3286 | } | 3388 | } |
859 | 3287 | 3389 | ||
860 | 3390 | /* RST | ||
861 | 3391 | .. attribute:: state | ||
862 | 3392 | |||
863 | 3393 | Query which state the ship is in: | ||
864 | 3394 | |||
865 | 3395 | - transport, | ||
866 | 3396 | - exp_waiting, exp_scouting, exp_found_port_space, exp_colonizing, | ||
867 | 3397 | - sink_request, sink_animation | ||
868 | 3398 | |||
869 | 3399 | (RW) returns the :class:`string` ship's state, or :const:`nil` if there is no valid state. | ||
870 | 3400 | |||
871 | 3401 | |||
872 | 3402 | */ | ||
873 | 3403 | // UNTESTED sink states | ||
874 | 3404 | int LuaShip::get_state(lua_State* L) { | ||
875 | 3405 | if (upcast(Game, game, &get_egbase(L))) { | ||
876 | 3406 | switch (get(L, get_egbase(L))->get_ship_state()) { | ||
877 | 3407 | case Ship::TRANSPORT: | ||
878 | 3408 | lua_pushstring(L, "transport"); | ||
879 | 3409 | break; | ||
880 | 3410 | case Ship::EXP_WAITING: | ||
881 | 3411 | lua_pushstring(L, "exp_waiting"); | ||
882 | 3412 | break; | ||
883 | 3413 | case Ship::EXP_SCOUTING: | ||
884 | 3414 | lua_pushstring(L, "exp_scouting"); | ||
885 | 3415 | break; | ||
886 | 3416 | case Ship::EXP_FOUNDPORTSPACE: | ||
887 | 3417 | lua_pushstring(L, "exp_found_port_space"); | ||
888 | 3418 | break; | ||
889 | 3419 | case Ship::EXP_COLONIZING: | ||
890 | 3420 | lua_pushstring(L, "exp_colonizing"); | ||
891 | 3421 | break; | ||
892 | 3422 | case Ship::SINK_REQUEST: | ||
893 | 3423 | lua_pushstring(L, "sink_request"); | ||
894 | 3424 | break; | ||
895 | 3425 | case Ship::SINK_ANIMATION: | ||
896 | 3426 | lua_pushstring(L, "sink_animation"); | ||
897 | 3427 | break; | ||
898 | 3428 | default: | ||
899 | 3429 | lua_pushnil(L); | ||
900 | 3430 | return 0; | ||
901 | 3431 | } | ||
902 | 3432 | return 1; | ||
903 | 3433 | } | ||
904 | 3434 | return 0; | ||
905 | 3435 | } | ||
906 | 3436 | |||
907 | 3437 | int LuaShip::get_scouting_direction(lua_State* L) { | ||
908 | 3438 | if (upcast(Game, game, &get_egbase(L))) { | ||
909 | 3439 | switch (get(L, get_egbase(L))->get_scouting_direction()) { | ||
910 | 3440 | case WalkingDir::WALK_NE: | ||
911 | 3441 | lua_pushstring(L, "ne"); | ||
912 | 3442 | break; | ||
913 | 3443 | case WalkingDir::WALK_E: | ||
914 | 3444 | lua_pushstring(L, "e"); | ||
915 | 3445 | break; | ||
916 | 3446 | case WalkingDir::WALK_SE: | ||
917 | 3447 | lua_pushstring(L, "se"); | ||
918 | 3448 | break; | ||
919 | 3449 | case WalkingDir::WALK_SW: | ||
920 | 3450 | lua_pushstring(L, "sw"); | ||
921 | 3451 | break; | ||
922 | 3452 | case WalkingDir::WALK_W: | ||
923 | 3453 | lua_pushstring(L, "w"); | ||
924 | 3454 | break; | ||
925 | 3455 | case WalkingDir::WALK_NW: | ||
926 | 3456 | lua_pushstring(L, "nw"); | ||
927 | 3457 | break; | ||
928 | 3458 | default: | ||
929 | 3459 | return 0; | ||
930 | 3460 | } | ||
931 | 3461 | return 1; | ||
932 | 3462 | } | ||
933 | 3463 | return 0; | ||
934 | 3464 | } | ||
935 | 3465 | |||
936 | 3466 | int LuaShip::set_scouting_direction(lua_State* L) { | ||
937 | 3467 | if (upcast(Game, game, &get_egbase(L))) { | ||
938 | 3468 | std::string dirname = luaL_checkstring(L, 3); | ||
939 | 3469 | WalkingDir dir = WalkingDir::IDLE; | ||
940 | 3470 | |||
941 | 3471 | if (dirname == "ne") { | ||
942 | 3472 | dir = WalkingDir::WALK_NE; | ||
943 | 3473 | } else if (dirname == "e") { | ||
944 | 3474 | dir = WalkingDir::WALK_E; | ||
945 | 3475 | } else if (dirname == "se") { | ||
946 | 3476 | dir = WalkingDir::WALK_SE; | ||
947 | 3477 | } else if (dirname == "sw") { | ||
948 | 3478 | dir = WalkingDir::WALK_SW; | ||
949 | 3479 | } else if (dirname == "w") { | ||
950 | 3480 | dir = WalkingDir::WALK_W; | ||
951 | 3481 | } else if (dirname == "nw") { | ||
952 | 3482 | dir = WalkingDir::WALK_NW; | ||
953 | 3483 | } else { | ||
954 | 3484 | return 0; | ||
955 | 3485 | } | ||
956 | 3486 | game->send_player_ship_scouting_direction(*get(L, get_egbase(L)), dir); | ||
957 | 3487 | return 1; | ||
958 | 3488 | } | ||
959 | 3489 | return 0; | ||
960 | 3490 | |||
961 | 3491 | } | ||
962 | 3492 | |||
963 | 3493 | /* RST | ||
964 | 3494 | .. attribute:: island_explore_direction | ||
965 | 3495 | |||
966 | 3496 | (RW) actual direction if the ship sails around an island. | ||
967 | 3497 | Sets/returns cw, ccw or nil | ||
968 | 3498 | |||
969 | 3499 | */ | ||
970 | 3500 | int LuaShip::get_island_explore_direction(lua_State* L) { | ||
971 | 3501 | if (upcast(Game, game, &get_egbase(L))) { | ||
972 | 3502 | switch (get(L, get_egbase(L))->get_island_explore_direction()) { | ||
973 | 3503 | case IslandExploreDirection::kCounterClockwise: | ||
974 | 3504 | lua_pushstring(L, "ccw"); | ||
975 | 3505 | break; | ||
976 | 3506 | case IslandExploreDirection::kClockwise: | ||
977 | 3507 | lua_pushstring(L, "cw"); | ||
978 | 3508 | break; | ||
979 | 3509 | default: | ||
980 | 3510 | return 0; | ||
981 | 3511 | } | ||
982 | 3512 | return 1; | ||
983 | 3513 | } | ||
984 | 3514 | return 0; | ||
985 | 3515 | } | ||
986 | 3516 | |||
987 | 3517 | int LuaShip::set_island_explore_direction(lua_State* L) { | ||
988 | 3518 | if (upcast(Game, game, &get_egbase(L))) { | ||
989 | 3519 | Ship* ship = get(L, get_egbase(L)); | ||
990 | 3520 | std::string dir = luaL_checkstring(L, 3); | ||
991 | 3521 | if (dir == "ccw"){ | ||
992 | 3522 | game->send_player_ship_explore_island(*ship, IslandExploreDirection::kCounterClockwise); | ||
993 | 3523 | } else if (dir == "cw") { | ||
994 | 3524 | game->send_player_ship_explore_island(*ship, IslandExploreDirection::kClockwise); | ||
995 | 3525 | } else { | ||
996 | 3526 | return 0; | ||
997 | 3527 | } | ||
998 | 3528 | return 1; | ||
999 | 3529 | } | ||
1000 | 3530 | return 0; | ||
1001 | 3531 | } | ||
1002 | 3532 | |||
1003 | 3288 | /* | 3533 | /* |
1004 | 3289 | ========================================================== | 3534 | ========================================================== |
1005 | 3290 | LUA METHODS | 3535 | LUA METHODS |
1006 | @@ -3341,6 +3586,25 @@ | |||
1007 | 3341 | return 1; | 3586 | return 1; |
1008 | 3342 | } | 3587 | } |
1009 | 3343 | 3588 | ||
1010 | 3589 | /* RST | ||
1011 | 3590 | .. method:: build_colonization_port() | ||
1012 | 3591 | |||
1013 | 3592 | Returns true if port space construction was started (ship was in adequate | ||
1014 | 3593 | status and a found portspace was nearby) | ||
1015 | 3594 | |||
1016 | 3595 | :returns: true/false | ||
1017 | 3596 | */ | ||
1018 | 3597 | int LuaShip::build_colonization_port(lua_State* L) { | ||
1019 | 3598 | Ship* ship = get(L, get_egbase(L)); | ||
1020 | 3599 | if (ship->get_ship_state() == Widelands::Ship::EXP_FOUNDPORTSPACE) { | ||
1021 | 3600 | if (upcast(Game, game, &get_egbase(L))) { | ||
1022 | 3601 | game->send_player_ship_construct_port(*ship, ship->exp_port_spaces()->front()); | ||
1023 | 3602 | return 1; | ||
1024 | 3603 | } | ||
1025 | 3604 | } | ||
1026 | 3605 | return 0; | ||
1027 | 3606 | } | ||
1028 | 3607 | |||
1029 | 3344 | /* | 3608 | /* |
1030 | 3345 | ========================================================== | 3609 | ========================================================== |
1031 | 3346 | C METHODS | 3610 | C METHODS |
1032 | 3347 | 3611 | ||
1033 | === modified file 'src/scripting/lua_map.h' | |||
1034 | --- src/scripting/lua_map.h 2015-02-12 21:03:20 +0000 | |||
1035 | +++ src/scripting/lua_map.h 2015-04-07 20:58:43 +0000 | |||
1036 | @@ -688,6 +688,7 @@ | |||
1037 | 688 | * Properties | 688 | * Properties |
1038 | 689 | */ | 689 | */ |
1039 | 690 | int get_portdock(lua_State* L); | 690 | int get_portdock(lua_State* L); |
1040 | 691 | int get_expedition_in_progress(lua_State* L); | ||
1041 | 691 | 692 | ||
1042 | 692 | /* | 693 | /* |
1043 | 693 | * Lua Methods | 694 | * Lua Methods |
1044 | @@ -698,6 +699,8 @@ | |||
1045 | 698 | int set_workers(lua_State*); | 699 | int set_workers(lua_State*); |
1046 | 699 | int set_soldiers(lua_State*); | 700 | int set_soldiers(lua_State*); |
1047 | 700 | int get_soldiers(lua_State*); | 701 | int get_soldiers(lua_State*); |
1048 | 702 | int start_expedition(lua_State*); | ||
1049 | 703 | int cancel_expedition(lua_State*); | ||
1050 | 701 | 704 | ||
1051 | 702 | /* | 705 | /* |
1052 | 703 | * C Methods | 706 | * C Methods |
1053 | @@ -806,6 +809,7 @@ | |||
1054 | 806 | /* | 809 | /* |
1055 | 807 | * Properties | 810 | * Properties |
1056 | 808 | */ | 811 | */ |
1057 | 812 | int get_field(lua_State *); | ||
1058 | 809 | int has_caps(lua_State *); | 813 | int has_caps(lua_State *); |
1059 | 810 | 814 | ||
1060 | 811 | /* | 815 | /* |
1061 | @@ -885,12 +889,17 @@ | |||
1062 | 885 | int get_debug_economy(lua_State * L); | 889 | int get_debug_economy(lua_State * L); |
1063 | 886 | int get_last_portdock(lua_State* L); | 890 | int get_last_portdock(lua_State* L); |
1064 | 887 | int get_destination(lua_State* L); | 891 | int get_destination(lua_State* L); |
1066 | 888 | 892 | int get_state(lua_State* L); | |
1067 | 893 | int get_scouting_direction(lua_State* L); | ||
1068 | 894 | int set_scouting_direction(lua_State* L); | ||
1069 | 895 | int get_island_explore_direction(lua_State* L); | ||
1070 | 896 | int set_island_explore_direction(lua_State* L); | ||
1071 | 889 | /* | 897 | /* |
1072 | 890 | * Lua methods | 898 | * Lua methods |
1073 | 891 | */ | 899 | */ |
1074 | 892 | int get_wares(lua_State* L); | 900 | int get_wares(lua_State* L); |
1075 | 893 | int get_workers(lua_State* L); | 901 | int get_workers(lua_State* L); |
1076 | 902 | int build_colonization_port(lua_State* L); | ||
1077 | 894 | 903 | ||
1078 | 895 | /* | 904 | /* |
1079 | 896 | * C methods | 905 | * C methods |
1080 | 897 | 906 | ||
1081 | === modified file 'src/wui/shipwindow.cc' | |||
1082 | --- src/wui/shipwindow.cc 2015-02-05 12:11:20 +0000 | |||
1083 | +++ src/wui/shipwindow.cc 2015-04-07 20:58:43 +0000 | |||
1084 | @@ -68,9 +68,9 @@ | |||
1085 | 68 | void act_destination(); | 68 | void act_destination(); |
1086 | 69 | void act_sink(); | 69 | void act_sink(); |
1087 | 70 | void act_cancel_expedition(); | 70 | void act_cancel_expedition(); |
1089 | 71 | void act_scout_towards(uint8_t); | 71 | void act_scout_towards(WalkingDir); |
1090 | 72 | void act_construct_port(); | 72 | void act_construct_port(); |
1092 | 73 | void act_explore_island(ScoutingDirection); | 73 | void act_explore_island(IslandExploreDirection); |
1093 | 74 | 74 | ||
1094 | 75 | private: | 75 | private: |
1095 | 76 | InteractiveGameBase & m_igbase; | 76 | InteractiveGameBase & m_igbase; |
1096 | @@ -120,7 +120,7 @@ | |||
1097 | 120 | m_btn_explore_island_cw = | 120 | m_btn_explore_island_cw = |
1098 | 121 | make_button | 121 | make_button |
1099 | 122 | (exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw, | 122 | (exp_top, "expcw", _("Explore the island’s coast clockwise"), pic_explore_cw, |
1101 | 123 | boost::bind(&ShipWindow::act_explore_island, this, ScoutingDirection::kClockwise)); | 123 | boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kClockwise)); |
1102 | 124 | exp_top->add(m_btn_explore_island_cw, 0, false); | 124 | exp_top->add(m_btn_explore_island_cw, 0, false); |
1103 | 125 | 125 | ||
1104 | 126 | m_btn_scout[WALK_NE - 1] = | 126 | m_btn_scout[WALK_NE - 1] = |
1105 | @@ -156,7 +156,7 @@ | |||
1106 | 156 | m_btn_explore_island_ccw = | 156 | m_btn_explore_island_ccw = |
1107 | 157 | make_button | 157 | make_button |
1108 | 158 | (exp_bot, "expccw", _("Explore the island’s coast counter clockwise"), pic_explore_ccw, | 158 | (exp_bot, "expccw", _("Explore the island’s coast counter clockwise"), pic_explore_ccw, |
1110 | 159 | boost::bind(&ShipWindow::act_explore_island, this, ScoutingDirection::kCounterClockwise)); | 159 | boost::bind(&ShipWindow::act_explore_island, this, IslandExploreDirection::kCounterClockwise)); |
1111 | 160 | exp_bot->add(m_btn_explore_island_ccw, 0, false); | 160 | exp_bot->add(m_btn_explore_island_ccw, 0, false); |
1112 | 161 | 161 | ||
1113 | 162 | m_btn_scout[WALK_SE - 1] = | 162 | m_btn_scout[WALK_SE - 1] = |
1114 | @@ -312,11 +312,11 @@ | |||
1115 | 312 | } | 312 | } |
1116 | 313 | 313 | ||
1117 | 314 | /// Sends a player command to the ship to scout towards a specific direction | 314 | /// Sends a player command to the ship to scout towards a specific direction |
1119 | 315 | void ShipWindow::act_scout_towards(uint8_t direction) { | 315 | void ShipWindow::act_scout_towards(WalkingDir direction) { |
1120 | 316 | // ignore request if the direction is not swimable at all | 316 | // ignore request if the direction is not swimable at all |
1122 | 317 | if (!m_ship.exp_dir_swimable(direction)) | 317 | if (!m_ship.exp_dir_swimable(static_cast<Direction>(direction))) |
1123 | 318 | return; | 318 | return; |
1125 | 319 | m_igbase.game().send_player_ship_scout_direction(m_ship, direction); | 319 | m_igbase.game().send_player_ship_scouting_direction(m_ship, direction); |
1126 | 320 | } | 320 | } |
1127 | 321 | 321 | ||
1128 | 322 | /// Constructs a port at the port build space in vision range | 322 | /// Constructs a port at the port build space in vision range |
1129 | @@ -327,7 +327,7 @@ | |||
1130 | 327 | } | 327 | } |
1131 | 328 | 328 | ||
1132 | 329 | /// Explores the island cw or ccw | 329 | /// Explores the island cw or ccw |
1134 | 330 | void ShipWindow::act_explore_island(ScoutingDirection direction) { | 330 | void ShipWindow::act_explore_island(IslandExploreDirection direction) { |
1135 | 331 | bool coast_nearby = false; | 331 | bool coast_nearby = false; |
1136 | 332 | bool moveable = false; | 332 | bool moveable = false; |
1137 | 333 | for (Direction dir = 1; (dir <= LAST_DIRECTION) && (!coast_nearby || !moveable); ++dir) { | 333 | for (Direction dir = 1; (dir <= LAST_DIRECTION) && (!coast_nearby || !moveable); ++dir) { |
1138 | 334 | 334 | ||
1139 | === modified file 'test/maps/expedition.wmf/scripting/init.lua' | |||
1140 | --- test/maps/expedition.wmf/scripting/init.lua 2014-08-01 15:30:12 +0000 | |||
1141 | +++ test/maps/expedition.wmf/scripting/init.lua 2015-04-07 20:58:43 +0000 | |||
1142 | @@ -93,24 +93,6 @@ | |||
1143 | 93 | assert_equal(1, port:get_workers("builder")) | 93 | assert_equal(1, port:get_workers("builder")) |
1144 | 94 | end | 94 | end |
1145 | 95 | 95 | ||
1146 | 96 | function start_expedition() | ||
1147 | 97 | assert_true(click_building(p1, "port")) | ||
1148 | 98 | sleep(100) | ||
1149 | 99 | assert_true(click_button("start_expedition")) | ||
1150 | 100 | sleep(100) | ||
1151 | 101 | close_windows() | ||
1152 | 102 | sleep(100) | ||
1153 | 103 | end | ||
1154 | 104 | |||
1155 | 105 | function cancel_expedition_in_port() | ||
1156 | 106 | assert_true(click_building(p1, "port")) | ||
1157 | 107 | sleep(100) | ||
1158 | 108 | assert_true(click_button("cancel_expedition")) | ||
1159 | 109 | sleep(100) | ||
1160 | 110 | close_windows() | ||
1161 | 111 | sleep(100) | ||
1162 | 112 | end | ||
1163 | 113 | |||
1164 | 114 | function cancel_expedition_in_shipwindow(which_ship) | 96 | function cancel_expedition_in_shipwindow(which_ship) |
1165 | 115 | click_on_ship(which_ship or first_ship) | 97 | click_on_ship(which_ship or first_ship) |
1166 | 116 | assert_true(click_button("cancel_expedition")) | 98 | assert_true(click_button("cancel_expedition")) |
1167 | @@ -174,7 +156,7 @@ | |||
1168 | 174 | game.desired_speed = 10 * 1000 | 156 | game.desired_speed = 10 * 1000 |
1169 | 175 | 157 | ||
1170 | 176 | -- Start a new expedition. | 158 | -- Start a new expedition. |
1172 | 177 | start_expedition() | 159 | port:start_expedition() |
1173 | 178 | wait_for_message("Expedition Ready") | 160 | wait_for_message("Expedition Ready") |
1174 | 179 | game.desired_speed = 10 * 1000 | 161 | game.desired_speed = 10 * 1000 |
1175 | 180 | sleep(10000) | 162 | sleep(10000) |
1176 | @@ -205,14 +187,15 @@ | |||
1177 | 205 | game.desired_speed = 10 * 1000 | 187 | game.desired_speed = 10 * 1000 |
1178 | 206 | 188 | ||
1179 | 207 | -- Start a new expedition. | 189 | -- Start a new expedition. |
1181 | 208 | start_expedition() | 190 | port:start_expedition() |
1182 | 209 | wait_for_message("Expedition Ready") | 191 | wait_for_message("Expedition Ready") |
1183 | 210 | game.desired_speed = 10 * 1000 | 192 | game.desired_speed = 10 * 1000 |
1184 | 211 | sleep(10000) | 193 | sleep(10000) |
1185 | 212 | 194 | ||
1189 | 213 | click_on_ship(first_ship) | 195 | first_ship.island_explore_direction="ccw" |
1190 | 214 | assert_true(click_button("expccw")) | 196 | sleep(2000) |
1191 | 215 | sleep(8000) | 197 | assert_equal("ccw",first_ship.island_explore_direction) |
1192 | 198 | sleep(6000) | ||
1193 | 216 | 199 | ||
1194 | 217 | stable_save("sailing") | 200 | stable_save("sailing") |
1195 | 218 | assert_equal(1, p1:get_workers("builder")) | 201 | assert_equal(1, p1:get_workers("builder")) |
1196 | @@ -235,13 +218,14 @@ | |||
1197 | 235 | game.desired_speed = 10 * 1000 | 218 | game.desired_speed = 10 * 1000 |
1198 | 236 | 219 | ||
1199 | 237 | -- Send expedition to port space. | 220 | -- Send expedition to port space. |
1201 | 238 | start_expedition() | 221 | port:start_expedition() |
1202 | 239 | wait_for_message("Expedition Ready") | 222 | wait_for_message("Expedition Ready") |
1203 | 240 | assert_equal(1, p1:get_workers("builder")) | 223 | assert_equal(1, p1:get_workers("builder")) |
1204 | 241 | sleep(500) | 224 | sleep(500) |
1205 | 242 | 225 | ||
1208 | 243 | click_on_ship(first_ship) | 226 | first_ship.island_explore_direction="ccw" |
1209 | 244 | assert_true(click_button("expccw")) | 227 | sleep(2000) |
1210 | 228 | assert_equal("ccw",first_ship.island_explore_direction) | ||
1211 | 245 | wait_for_message("Port Space Found") | 229 | wait_for_message("Port Space Found") |
1212 | 246 | sleep(500) | 230 | sleep(500) |
1213 | 247 | assert_equal(1, p1:get_workers("builder")) | 231 | assert_equal(1, p1:get_workers("builder")) |
1214 | @@ -272,12 +256,13 @@ | |||
1215 | 272 | port:set_wares("blackwood", 100) | 256 | port:set_wares("blackwood", 100) |
1216 | 273 | 257 | ||
1217 | 274 | 258 | ||
1219 | 275 | start_expedition() | 259 | port:start_expedition() |
1220 | 276 | wait_for_message("Expedition Ready") | 260 | wait_for_message("Expedition Ready") |
1223 | 277 | click_on_ship(first_ship) | 261 | first_ship.island_explore_direction="ccw" |
1224 | 278 | assert_true(click_button("expccw")) | 262 | sleep(2000) |
1225 | 263 | assert_equal("ccw",first_ship.island_explore_direction) | ||
1226 | 279 | wait_for_message("Port Space Found") | 264 | wait_for_message("Port Space Found") |
1228 | 280 | assert_true(click_button("buildport")) | 265 | first_ship:build_colonization_port() |
1229 | 281 | sleep(500) | 266 | sleep(500) |
1230 | 282 | assert_equal(1, p1:get_workers("builder")) | 267 | assert_equal(1, p1:get_workers("builder")) |
1231 | 283 | wait_for_message("Port") | 268 | wait_for_message("Port") |
1232 | 284 | 269 | ||
1233 | === added file 'test/maps/expedition.wmf/scripting/test_ship_movement_controls.lua' | |||
1234 | --- test/maps/expedition.wmf/scripting/test_ship_movement_controls.lua 1970-01-01 00:00:00 +0000 | |||
1235 | +++ test/maps/expedition.wmf/scripting/test_ship_movement_controls.lua 2015-04-07 20:58:43 +0000 | |||
1236 | @@ -0,0 +1,115 @@ | |||
1237 | 1 | run(function() | ||
1238 | 2 | game.desired_speed = 30 * 1000 | ||
1239 | 3 | p1:place_bob("ship", map:get_field(10, 10)) | ||
1240 | 4 | |||
1241 | 5 | port = map:get_field(16, 16).immovable | ||
1242 | 6 | port:set_wares("log", 10) -- no sense to wait | ||
1243 | 7 | port:set_wares("blackwood", 10) | ||
1244 | 8 | |||
1245 | 9 | --getting table with all our ships (single one only) | ||
1246 | 10 | ships = p1:get_ships() | ||
1247 | 11 | |||
1248 | 12 | --veryfing that ship is indeed placed where should be :) | ||
1249 | 13 | assert_equal(10,ships[1].field.x) | ||
1250 | 14 | assert_equal(10,ships[1].field.y) | ||
1251 | 15 | |||
1252 | 16 | --ships table should contain 1 item (1 ship) | ||
1253 | 17 | assert_equal(1, #ships) | ||
1254 | 18 | |||
1255 | 19 | --ship has no wares on it | ||
1256 | 20 | assert_equal(0,ships[1]:get_wares()) | ||
1257 | 21 | |||
1258 | 22 | --no destination is set | ||
1259 | 23 | assert(not ships[1].destination) | ||
1260 | 24 | |||
1261 | 25 | --ships in transport state | ||
1262 | 26 | assert_equal("transport", ships[1].state) | ||
1263 | 27 | |||
1264 | 28 | --the warehouse is probably not in expedition state :) | ||
1265 | 29 | assert(not map:get_field(8, 18).immovable.expedition_in_progress) | ||
1266 | 30 | |||
1267 | 31 | --starting prepartion for expedition | ||
1268 | 32 | assert(not port.expedition_in_progress) | ||
1269 | 33 | port:start_expedition() | ||
1270 | 34 | sleep (300) | ||
1271 | 35 | assert(port.expedition_in_progress) | ||
1272 | 36 | |||
1273 | 37 | --ships changes state when exp ready | ||
1274 | 38 | while ships[1].state == "transport" do sleep(2000) end | ||
1275 | 39 | assert_equal("exp_waiting", ships[1].state) | ||
1276 | 40 | |||
1277 | 41 | --sending NW and verifying | ||
1278 | 42 | ships[1].scouting_direction="nw" | ||
1279 | 43 | sleep(6000) | ||
1280 | 44 | assert_equal("nw", ships[1].scouting_direction) | ||
1281 | 45 | assert_equal("exp_scouting", ships[1].state) | ||
1282 | 46 | |||
1283 | 47 | while ships[1].scouting_direction == "nw" do | ||
1284 | 48 | sleep (2000) | ||
1285 | 49 | end | ||
1286 | 50 | |||
1287 | 51 | --now ships stops nearby NW coast, so sending it back | ||
1288 | 52 | ships[1].scouting_direction="se" | ||
1289 | 53 | sleep(4000) | ||
1290 | 54 | assert_equal("se", ships[1].scouting_direction) | ||
1291 | 55 | |||
1292 | 56 | --testing remaining directions | ||
1293 | 57 | ships[1].scouting_direction="e" | ||
1294 | 58 | sleep(2000) | ||
1295 | 59 | assert_equal("e", ships[1].scouting_direction) | ||
1296 | 60 | |||
1297 | 61 | ships[1].scouting_direction="w" | ||
1298 | 62 | sleep(2000) | ||
1299 | 63 | assert_equal("w", ships[1].scouting_direction) | ||
1300 | 64 | |||
1301 | 65 | ships[1].scouting_direction="sw" | ||
1302 | 66 | sleep(2000) | ||
1303 | 67 | assert_equal("sw", ships[1].scouting_direction) | ||
1304 | 68 | |||
1305 | 69 | ships[1].scouting_direction="ne" | ||
1306 | 70 | sleep(2000) | ||
1307 | 71 | assert_equal("ne", ships[1].scouting_direction) | ||
1308 | 72 | |||
1309 | 73 | --back to original course | ||
1310 | 74 | ships[1].scouting_direction="se" | ||
1311 | 75 | sleep(2000) | ||
1312 | 76 | assert_equal("se", ships[1].scouting_direction) | ||
1313 | 77 | |||
1314 | 78 | --waiting till it stops (no direction/nil is returned) | ||
1315 | 79 | while ships[1].scouting_direction do sleep(2000) end | ||
1316 | 80 | |||
1317 | 81 | --sending to scout the island | ||
1318 | 82 | ships[1].island_explore_direction="ccw"; | ||
1319 | 83 | sleep(3000) | ||
1320 | 84 | assert_equal("ccw", ships[1].island_explore_direction) | ||
1321 | 85 | assert_equal("exp_scouting", ships[1].state) | ||
1322 | 86 | |||
1323 | 87 | --fine, now change the direction | ||
1324 | 88 | ships[1].island_explore_direction="cw"; | ||
1325 | 89 | sleep(3000) | ||
1326 | 90 | assert_equal("cw", ships[1].island_explore_direction) | ||
1327 | 91 | |||
1328 | 92 | -- wait till it finds a port | ||
1329 | 93 | wait_for_message("Port Space Found") | ||
1330 | 94 | sleep(500) | ||
1331 | 95 | assert_equal("exp_found_port_space", ships[1].state) | ||
1332 | 96 | |||
1333 | 97 | --starting colonization port here | ||
1334 | 98 | assert(ships[1]:build_colonization_port()) | ||
1335 | 99 | sleep(500) | ||
1336 | 100 | assert_equal("exp_colonizing", ships[1].state) | ||
1337 | 101 | sleep(15000) | ||
1338 | 102 | stable_save("port_in_constr") | ||
1339 | 103 | |||
1340 | 104 | -- while unfinished yet, removing it | ||
1341 | 105 | new_port=map:get_field(16,2).immovable | ||
1342 | 106 | assert(new_port) | ||
1343 | 107 | new_port:remove() | ||
1344 | 108 | sleep(3000) | ||
1345 | 109 | |||
1346 | 110 | --yes, the ships is back in transport mode | ||
1347 | 111 | assert_equal("transport", ships[1].state) | ||
1348 | 112 | |||
1349 | 113 | print("# All Tests passed.") | ||
1350 | 114 | wl.ui.MapView():close() | ||
1351 | 115 | end) | ||
1352 | 0 | 116 | ||
1353 | === modified file 'test/maps/expedition.wmf/scripting/test_starting_and_immediately_canceling.lua' | |||
1354 | --- test/maps/expedition.wmf/scripting/test_starting_and_immediately_canceling.lua 2013-10-29 20:22:08 +0000 | |||
1355 | +++ test/maps/expedition.wmf/scripting/test_starting_and_immediately_canceling.lua 2015-04-07 20:58:43 +0000 | |||
1356 | @@ -5,8 +5,12 @@ | |||
1357 | 5 | 5 | ||
1358 | 6 | -- Start and immediately cancel an expedition. | 6 | -- Start and immediately cancel an expedition. |
1359 | 7 | print("---- 1 -----") | 7 | print("---- 1 -----") |
1362 | 8 | start_expedition() | 8 | port:start_expedition() |
1363 | 9 | cancel_expedition_in_port() | 9 | sleep(500) |
1364 | 10 | assert(port.expedition_in_progress) | ||
1365 | 11 | port:cancel_expedition() | ||
1366 | 12 | sleep(500) | ||
1367 | 13 | assert(not port.expedition_in_progress) | ||
1368 | 10 | sleep(500) | 14 | sleep(500) |
1369 | 11 | assert_equal(1, p1:get_workers("builder")) | 15 | assert_equal(1, p1:get_workers("builder")) |
1370 | 12 | 16 | ||
1371 | 13 | 17 | ||
1372 | === modified file 'test/maps/expedition.wmf/scripting/test_starting_wait_a_while_cancel.lua' | |||
1373 | --- test/maps/expedition.wmf/scripting/test_starting_wait_a_while_cancel.lua 2013-10-29 20:22:08 +0000 | |||
1374 | +++ test/maps/expedition.wmf/scripting/test_starting_wait_a_while_cancel.lua 2015-04-07 20:58:43 +0000 | |||
1375 | @@ -4,12 +4,12 @@ | |||
1376 | 4 | 4 | ||
1377 | 5 | -- Start an expedition, but let them carry some wares into it. This also | 5 | -- Start an expedition, but let them carry some wares into it. This also |
1378 | 6 | -- gives the builder enough time to walk over. | 6 | -- gives the builder enough time to walk over. |
1380 | 7 | start_expedition() | 7 | port:start_expedition() |
1381 | 8 | sleep(50000) | 8 | sleep(50000) |
1382 | 9 | stable_save("cancel_in_port") | 9 | stable_save("cancel_in_port") |
1383 | 10 | assert_equal(1, p1:get_workers("builder")) | 10 | assert_equal(1, p1:get_workers("builder")) |
1384 | 11 | 11 | ||
1386 | 12 | cancel_expedition_in_port() | 12 | port:cancel_expedition() |
1387 | 13 | sleep(500) | 13 | sleep(500) |
1388 | 14 | assert_equal(1, p1:get_workers("builder")) | 14 | assert_equal(1, p1:get_workers("builder")) |
1389 | 15 | 15 | ||
1390 | 16 | 16 | ||
1391 | === modified file 'test/maps/ship_transportation.wmf/scripting/init.lua' | |||
1392 | --- test/maps/ship_transportation.wmf/scripting/init.lua 2015-02-10 21:25:14 +0000 | |||
1393 | +++ test/maps/ship_transportation.wmf/scripting/init.lua 2015-04-07 20:58:43 +0000 | |||
1394 | @@ -37,23 +37,6 @@ | |||
1395 | 37 | return nil | 37 | return nil |
1396 | 38 | end | 38 | end |
1397 | 39 | 39 | ||
1398 | 40 | function portdock2() | ||
1399 | 41 | local portdock = map:get_field(15, 4).immovable | ||
1400 | 42 | if portdock then | ||
1401 | 43 | return portdock | ||
1402 | 44 | end | ||
1403 | 45 | local portdock = map:get_field(14, 5).immovable | ||
1404 | 46 | if portdock then | ||
1405 | 47 | return portdock | ||
1406 | 48 | end | ||
1407 | 49 | local portdock = map:get_field(14, 4).immovable | ||
1408 | 50 | if portdock then | ||
1409 | 51 | return portdock | ||
1410 | 52 | end | ||
1411 | 53 | print ("portdock not found") | ||
1412 | 54 | return nill | ||
1413 | 55 | end | ||
1414 | 56 | |||
1415 | 57 | function start_building_farm() | 40 | function start_building_farm() |
1416 | 58 | p1:place_building("farm", map:get_field(18, 4), true, true) | 41 | p1:place_building("farm", map:get_field(18, 4), true, true) |
1417 | 59 | connected_road(p1, map:get_field(18,5).immovable, "l,l|tl,tr|", true) | 42 | connected_road(p1, map:get_field(18,5).immovable, "l,l|tl,tr|", true) |
1418 | 60 | 43 | ||
1419 | === modified file 'test/maps/ship_transportation.wmf/scripting/test_rip_portdock_with_worker_and_ware_in_transit.lua' | |||
1420 | --- test/maps/ship_transportation.wmf/scripting/test_rip_portdock_with_worker_and_ware_in_transit.lua 2015-02-10 21:25:14 +0000 | |||
1421 | +++ test/maps/ship_transportation.wmf/scripting/test_rip_portdock_with_worker_and_ware_in_transit.lua 2015-04-07 20:58:43 +0000 | |||
1422 | @@ -32,7 +32,9 @@ | |||
1423 | 32 | stable_save("restored_port") | 32 | stable_save("restored_port") |
1424 | 33 | 33 | ||
1425 | 34 | -- remove the portdock while the blackwood is in transit. | 34 | -- remove the portdock while the blackwood is in transit. |
1427 | 35 | portdock2():remove() | 35 | port2_portdock=port2().portdock |
1428 | 36 | assert(port2_portdock) | ||
1429 | 37 | port2_portdock:remove() | ||
1430 | 36 | 38 | ||
1431 | 37 | sleep(5000) | 39 | sleep(5000) |
1432 | 38 | 40 | ||
1433 | 39 | 41 | ||
1434 | === modified file 'test/maps/ship_transportation.wmf/scripting/test_rip_second_port_with_worker_in_portdock.lua' | |||
1435 | --- test/maps/ship_transportation.wmf/scripting/test_rip_second_port_with_worker_in_portdock.lua 2014-01-18 12:40:08 +0000 | |||
1436 | +++ test/maps/ship_transportation.wmf/scripting/test_rip_second_port_with_worker_in_portdock.lua 2015-04-07 20:58:43 +0000 | |||
1437 | @@ -5,6 +5,13 @@ | |||
1438 | 5 | create_first_port() | 5 | create_first_port() |
1439 | 6 | create_second_port() | 6 | create_second_port() |
1440 | 7 | 7 | ||
1441 | 8 | --removing portdock first | ||
1442 | 9 | portdock_fields=port2().portdock.fields | ||
1443 | 10 | portdock_fields[1].immovable:remove() | ||
1444 | 11 | sleep(100) | ||
1445 | 12 | --portdock should be back, as port is still there | ||
1446 | 13 | assert (portdock_fields[1].immovable) | ||
1447 | 14 | |||
1448 | 8 | start_building_farm() | 15 | start_building_farm() |
1449 | 9 | port1():set_workers{ | 16 | port1():set_workers{ |
1450 | 10 | builder = 1, | 17 | builder = 1, |
1451 | @@ -16,8 +23,13 @@ | |||
1452 | 16 | assert_equal(p1:get_workers("builder"), 1) | 23 | assert_equal(p1:get_workers("builder"), 1) |
1453 | 17 | assert_equal(port1():get_workers("builder"), 0) | 24 | assert_equal(port1():get_workers("builder"), 0) |
1454 | 18 | 25 | ||
1455 | 26 | portdock_fields=port2().portdock.fields | ||
1456 | 19 | port2():remove() | 27 | port2():remove() |
1457 | 20 | sleep(100) | 28 | sleep(100) |
1458 | 29 | --verify that also portdock was removed | ||
1459 | 30 | assert (not portdock_fields[1].immovable) | ||
1460 | 31 | |||
1461 | 32 | sleep(100) | ||
1462 | 21 | 33 | ||
1463 | 22 | stable_save("worker_in_portdock") | 34 | stable_save("worker_in_portdock") |
1464 | 23 | 35 |
I just had a very quick look and it seems to be OK overall - I will have to look at the code properly. One thing though: it might be better to have strings rather than numbers in Lua for the scouting direction. Operating on the pure numbers will make the code hard to read, and also break the code if the C++ enum should change.