1
- use crate :: content:: custom_phase_actions:: { PlayerRequest , PositionRequest , ResourceRewardRequest } ;
2
- use crate :: game:: Game ;
3
- use crate :: incident:: { Incident , IncidentBaseEffect , IncidentBuilder } ;
4
- use crate :: payment:: PaymentOptions ;
5
- use crate :: player_events:: IncidentTarget ;
6
- use crate :: resource:: ResourceType ;
7
- use crate :: unit:: UnitType ;
1
+ use crate :: content:: incidents_1:: { good_year, pestilence} ;
2
+ use crate :: content:: incidents_2:: population_boom;
3
+ use crate :: content:: incidents_5:: successful_year;
4
+ use crate :: incident:: Incident ;
8
5
use itertools:: Itertools ;
9
6
use std:: vec;
10
7
11
8
#[ must_use]
12
9
pub ( crate ) fn get_all ( ) -> Vec < Incident > {
13
- let all = vec ! [ good_year( ) , population_boom( ) , successful_year( ) ]
14
- . into_iter ( )
15
- . flatten ( )
16
- . collect_vec ( ) ;
10
+ let all = vec ! [
11
+ // 1+
12
+ pestilence( ) ,
13
+ good_year( ) ,
14
+ // 11+
15
+ population_boom( ) ,
16
+ // 51+
17
+ successful_year( ) ,
18
+ ]
19
+ . into_iter ( )
20
+ . flatten ( )
21
+ . collect_vec ( ) ;
17
22
assert_eq ! (
18
23
all. iter( ) . unique_by( |i| i. id) . count( ) ,
19
24
all. len( ) ,
@@ -22,171 +27,6 @@ pub(crate) fn get_all() -> Vec<Incident> {
22
27
all
23
28
}
24
29
25
- fn population_boom ( ) -> Vec < Incident > {
26
- let mut b = Incident :: builder (
27
- 28 ,
28
- "Population Boom" ,
29
- "-" ,
30
- IncidentBaseEffect :: BarbariansMove ,
31
- ) ;
32
- b = select_settler ( b, 2 , |game, _| {
33
- game. current_custom_phase ( ) . is_active_player ( )
34
- } ) ;
35
- b = b. add_incident_player_request (
36
- IncidentTarget :: ActivePlayer ,
37
- 1 ,
38
- |game, player_index, _incident| {
39
- let choices = game
40
- . players
41
- . iter ( )
42
- . filter ( |p| p. available_units ( ) . settlers > 0 && p. index != player_index)
43
- . map ( |p| p. index )
44
- . collect_vec ( ) ;
45
-
46
- if choices. is_empty ( ) {
47
- None
48
- } else {
49
- Some ( PlayerRequest :: new (
50
- choices,
51
- "Select a unit to gain 1 settler" ,
52
- ) )
53
- }
54
- } ,
55
- |game, c| {
56
- game. add_info_log_item ( & format ! (
57
- "{} was selected to gain 1 settler from Population Boom" ,
58
- game. get_player( c. choice) . get_name( )
59
- ) ) ;
60
- game. current_custom_phase_mut ( ) . selected_player = Some ( c. choice ) ;
61
- } ,
62
- ) ;
63
- b = select_settler ( b, 0 , |game, player| {
64
- let c = game. current_custom_phase ( ) ;
65
- c. selected_player == Some ( player)
66
- } ) ;
67
- vec ! [ b. build( ) ]
68
- }
69
-
70
- fn select_settler (
71
- b : IncidentBuilder ,
72
- priority : i32 ,
73
- pred : impl Fn ( & Game , usize ) -> bool + ' static + Clone ,
74
- ) -> IncidentBuilder {
75
- b. add_incident_position_request (
76
- IncidentTarget :: AllPlayers ,
77
- priority,
78
- move |game, player_index, _incident| {
79
- let p = game. get_player ( player_index) ;
80
- if pred ( game, player_index) && p. available_units ( ) . settlers > 0 {
81
- Some ( PositionRequest :: new (
82
- p. cities . iter ( ) . map ( |c| c. position ) . collect ( ) ,
83
- Some ( "Select a city to gain 1 settler" . to_string ( ) ) ,
84
- ) )
85
- } else {
86
- None
87
- }
88
- } ,
89
- |game, s| {
90
- game. add_info_log_item ( & format ! (
91
- "{} gained 1 settler in {}" ,
92
- s. player_name, s. choice
93
- ) ) ;
94
- game. get_player_mut ( s. player_index )
95
- . add_unit ( s. choice , UnitType :: Settler ) ;
96
- } ,
97
- )
98
- }
99
-
100
- fn successful_year ( ) -> Vec < Incident > {
101
- vec ! [ Incident :: builder(
102
- 54 ,
103
- "A successful year" ,
104
- "-" ,
105
- IncidentBaseEffect :: PiratesSpawnAndRaid ,
106
- )
107
- . add_incident_resource_request(
108
- IncidentTarget :: AllPlayers ,
109
- 0 ,
110
- |game, player_index, _incident| {
111
- let player_to_city_num = game
112
- . players
113
- . iter( )
114
- . map( |p| p. cities. len( ) )
115
- . collect:: <Vec <_>>( ) ;
116
-
117
- let min_cities = player_to_city_num. iter( ) . min( ) . unwrap_or( & 0 ) ;
118
- let max_cities = player_to_city_num. iter( ) . max( ) . unwrap_or( & 0 ) ;
119
- if min_cities == max_cities {
120
- return Some ( ResourceRewardRequest :: new(
121
- PaymentOptions :: sum( 1 , & [ ResourceType :: Food ] ) ,
122
- "-" . to_string( ) ,
123
- ) ) ;
124
- }
125
-
126
- let cities = game. players[ player_index] . cities. len( ) ;
127
- if cities == * min_cities {
128
- Some ( ResourceRewardRequest :: new(
129
- PaymentOptions :: sum( ( max_cities - min_cities) as u32 , & [ ResourceType :: Food ] ) ,
130
- "-" . to_string( ) ,
131
- ) )
132
- } else {
133
- None
134
- }
135
- } ,
136
- |_game, s| {
137
- vec![ format!(
138
- "{} gained {} from A successful year" ,
139
- s. player_name, s. choice
140
- ) ]
141
- } ,
142
- )
143
- . build( ) ]
144
- }
145
-
146
- fn good_year ( ) -> Vec < Incident > {
147
- vec ! [
148
- add_good_year(
149
- IncidentTarget :: AllPlayers ,
150
- Incident :: builder(
151
- 9 ,
152
- "A good year" ,
153
- "Every player gains 1 food" ,
154
- IncidentBaseEffect :: BarbariansSpawn ,
155
- ) ,
156
- ) ,
157
- add_good_year(
158
- IncidentTarget :: ActivePlayer ,
159
- Incident :: builder(
160
- 10 ,
161
- "A good year" ,
162
- "You gain 1 food" ,
163
- IncidentBaseEffect :: BarbariansSpawn ,
164
- ) ,
165
- ) ,
166
- ]
167
- }
168
-
169
- fn add_good_year ( target : IncidentTarget , builder : IncidentBuilder ) -> Incident {
170
- builder
171
- . add_incident_resource_request (
172
- target,
173
- 0 ,
174
- |_game, _player_index, _incident| {
175
- Some ( ResourceRewardRequest :: new (
176
- PaymentOptions :: sum ( 1 , & [ ResourceType :: Food ] ) ,
177
- "Gain 1 food" . to_string ( ) ,
178
- ) )
179
- } ,
180
- |_game, s| {
181
- vec ! [ format!(
182
- "{} gained {} from A good year" ,
183
- s. player_name, s. choice
184
- ) ]
185
- } ,
186
- )
187
- . build ( )
188
- }
189
-
190
30
///
191
31
/// # Panics
192
32
/// Panics if incident does not exist
0 commit comments