1
1
use crate :: advance:: gain_advance;
2
2
use crate :: combat:: {
3
- combat_loop, combat_round_end, end_combat, move_with_possible_combat, start_combat, take_combat ,
3
+ combat_loop, combat_round_end, end_combat, move_with_possible_combat, start_combat,
4
4
} ;
5
5
use crate :: content:: custom_phase_actions:: { CurrentEventResponse , CurrentEventType } ;
6
6
use crate :: cultural_influence:: ask_for_cultural_influence_payment;
7
7
use crate :: explore:: { ask_explore_resolution, move_to_unexplored_tile} ;
8
- use crate :: game:: GameState :: { Combat , Finished , Movement , Playing , StatusPhase } ;
8
+ use crate :: game:: GameState :: { Finished , Movement , Playing } ;
9
9
use crate :: game:: { ActionLogItem , Game , GameState } ;
10
10
use crate :: incident:: trigger_incident;
11
11
use crate :: log;
12
12
use crate :: map:: Terrain :: Unexplored ;
13
13
use crate :: movement:: {
14
- has_movable_units , move_units_destinations , take_move_state , CurrentMove , MoveState ,
14
+ get_move_state , has_movable_units , move_units_destinations , CurrentMove , MoveState ,
15
15
} ;
16
16
use crate :: playing_actions:: PlayingAction ;
17
17
use crate :: recruit:: on_recruit;
@@ -148,19 +148,18 @@ pub(crate) fn execute_custom_phase_action(
148
148
InfluenceCultureResolution ( r) => {
149
149
ask_for_cultural_influence_payment ( game, player_index, r) ;
150
150
}
151
- CombatStart => {
152
- start_combat ( game) ;
151
+ CombatStart ( c ) => {
152
+ start_combat ( game, c . clone ( ) ) ;
153
153
}
154
154
CombatRoundEnd ( r) => {
155
155
if let Some ( c) = combat_round_end ( game, r) {
156
156
combat_loop ( game, c) ;
157
157
}
158
158
}
159
159
CombatEnd ( r) => {
160
- let c = take_combat ( game) ;
161
- end_combat ( game, c, r. clone ( ) ) ;
160
+ end_combat ( game, r) ;
162
161
}
163
- StatusPhase => play_status_phase ( game) ,
162
+ StatusPhase ( s ) => play_status_phase ( game, s . clone ( ) ) ,
164
163
TurnStart => game. start_turn ( ) ,
165
164
Advance ( a) => {
166
165
gain_advance ( game, player_index, a) ;
@@ -182,12 +181,16 @@ pub(crate) fn add_log_item_from_action(game: &mut Game, action: &Action) {
182
181
}
183
182
184
183
fn execute_regular_action ( game : & mut Game , action : Action , player_index : usize ) {
185
- match game. state ( ) {
184
+ match game. state {
186
185
Playing => {
187
186
if let Some ( m) = action. clone ( ) . movement ( ) {
187
+ if let MovementAction :: Move ( _) = m {
188
+ } else {
189
+ panic ! ( "Illegal action" ) ;
190
+ }
188
191
assert_ne ! ( game. actions_left, 0 , "Illegal action" ) ;
189
192
game. actions_left -= 1 ;
190
- game. push_state ( GameState :: Movement ( MoveState :: new ( ) ) ) ;
193
+ game. state = GameState :: Movement ( MoveState :: new ( ) ) ;
191
194
execute_movement_action ( game, m, player_index) ;
192
195
} else {
193
196
let action = action. playing ( ) . expect ( "action should be a playing action" ) ;
@@ -200,12 +203,6 @@ fn execute_regular_action(game: &mut Game, action: Action, player_index: usize)
200
203
. expect ( "action should be a movement action" ) ;
201
204
execute_movement_action ( game, action, player_index) ;
202
205
}
203
- Combat ( _) => {
204
- panic ! ( "actions can't be executed when the game is in a combat state" ) ;
205
- }
206
- StatusPhase ( _) => {
207
- panic ! ( "actions can't be executed when the game is in a status state" ) ;
208
- }
209
206
Finished => panic ! ( "actions can't be executed when the game is finished" ) ,
210
207
}
211
208
}
@@ -247,16 +244,16 @@ pub(crate) fn execute_movement_action(
247
244
}
248
245
}
249
246
250
- let mut move_state = take_move_state ( game) ;
251
- move_state. moved_units . extend ( m. units . iter ( ) ) ;
252
- move_state. moved_units = move_state. moved_units . iter ( ) . unique ( ) . copied ( ) . collect ( ) ;
253
247
let current_move = get_current_move (
254
248
game,
255
249
& m. units ,
256
250
starting_position,
257
251
m. destination ,
258
252
m. embark_carrier_id ,
259
253
) ;
254
+ let move_state = get_move_state ( game) ;
255
+ move_state. moved_units . extend ( m. units . iter ( ) ) ;
256
+ move_state. moved_units = move_state. moved_units . iter ( ) . unique ( ) . copied ( ) . collect ( ) ;
260
257
261
258
if matches ! ( current_move, CurrentMove :: None ) || move_state. current_move != current_move
262
259
{
@@ -267,7 +264,6 @@ pub(crate) fn execute_movement_action(
267
264
// roads move ends the current move
268
265
move_state. current_move = CurrentMove :: None ;
269
266
}
270
- game. push_state ( GameState :: Movement ( move_state) ) ;
271
267
272
268
let dest_terrain = game
273
269
. map
@@ -290,16 +286,15 @@ pub(crate) fn execute_movement_action(
290
286
}
291
287
}
292
288
Stop => {
293
- game. pop_state ( ) ;
289
+ game. state = GameState :: Playing ;
294
290
return ;
295
291
}
296
292
} ;
297
293
298
- let state = take_move_state ( game) ;
294
+ let state = get_move_state ( game) ;
299
295
let all_moves_used =
300
296
state. movement_actions_left == 0 && state. current_move == CurrentMove :: None ;
301
297
if all_moves_used || !has_movable_units ( game, game. get_player ( game. current_player_index ) ) {
302
- return ;
298
+ game . state = GameState :: Playing ;
303
299
}
304
- game. push_state ( GameState :: Movement ( state) ) ;
305
300
}
0 commit comments