@@ -13,7 +13,8 @@ use crate::{
13
13
planet:: Planet ,
14
14
player:: { Player , Trait } ,
15
15
position:: MAX_POSITION ,
16
- skill:: GameSkill ,
16
+ role:: CrewRole ,
17
+ skill:: { GameSkill , MAX_SKILL } ,
17
18
} ,
18
19
} ;
19
20
use itertools:: Itertools ;
@@ -186,10 +187,10 @@ impl<'game> Game {
186
187
let seed = game. get_rng_seed ( ) ;
187
188
let mut rng = ChaCha8Rng :: from_seed ( seed) ;
188
189
189
- let attendance =
190
- ( BASE_ATTENDANCE + total_reputation. value ( ) as u32 * planet. total_population ( ) ) as f32
191
- * rng. gen_range ( 0.75 ..1.25 )
192
- * ( 1.0 + bonus_attendance) ;
190
+ let attendance = ( BASE_ATTENDANCE as f32
191
+ + ( total_reputation. value ( ) as f32 ) . powf ( 2.0 ) * planet. total_population ( ) as f32 )
192
+ * rng. gen_range ( 0.75 ..1.25 )
193
+ * ( 1.0 + bonus_attendance) ;
193
194
game. attendance = attendance as u32 ;
194
195
let mut default_output = ActionOutput :: default ( ) ;
195
196
@@ -424,6 +425,26 @@ impl<'game> Game {
424
425
Possession :: Away => ( defense_stats, attack_stats) ,
425
426
} ;
426
427
428
+ // Conditions for morale boost:
429
+ // shot success, team is losing at most by a margin equal to the captain charisma.
430
+ let attacking_player = self . attacking_players ( ) ;
431
+ let team_captain = attacking_player
432
+ . iter ( )
433
+ . find ( |& p| p. info . crew_role == CrewRole :: Captain ) ;
434
+
435
+ let mut losing_margin = 4 ;
436
+
437
+ if let Some ( captain) = team_captain {
438
+ losing_margin += ( captain. mental . charisma / 4.0 ) as u16
439
+ } ;
440
+
441
+ let score = self . get_score ( ) ;
442
+
443
+ let is_losing_by_margin = match self . possession {
444
+ Possession :: Home => score. 0 < score. 1 && score. 1 - score. 0 <= losing_margin,
445
+ Possession :: Away => score. 1 < score. 0 && score. 0 - score. 1 <= losing_margin,
446
+ } ;
447
+
427
448
if let Some ( updates) = & mut home_stats {
428
449
for ( id, player_stats) in self . home_team_in_game . stats . iter_mut ( ) {
429
450
let player = self . home_team_in_game . players . get_mut ( & id) . unwrap ( ) ;
@@ -437,7 +458,15 @@ impl<'game> Game {
437
458
if self . possession == Possession :: Home {
438
459
player. add_morale ( MoraleModifier :: SMALL_BONUS ) ;
439
460
} else {
440
- player. add_morale ( MoraleModifier :: SMALL_MALUS ) ;
461
+ player. add_morale (
462
+ MoraleModifier :: SMALL_MALUS
463
+ / ( 1.0 + player. mental . charisma / MAX_SKILL ) ,
464
+ ) ;
465
+ }
466
+
467
+ if is_losing_by_margin {
468
+ player
469
+ . add_morale ( MoraleModifier :: SMALL_BONUS + player. mental . charisma / 8.0 ) ;
441
470
}
442
471
}
443
472
}
@@ -456,7 +485,15 @@ impl<'game> Game {
456
485
if self . possession == Possession :: Away {
457
486
player. add_morale ( MoraleModifier :: SMALL_BONUS ) ;
458
487
} else {
459
- player. add_morale ( MoraleModifier :: SMALL_MALUS ) ;
488
+ player. add_morale (
489
+ MoraleModifier :: SMALL_MALUS
490
+ / ( 1.0 + player. mental . charisma / MAX_SKILL ) ,
491
+ ) ;
492
+ }
493
+
494
+ if is_losing_by_margin {
495
+ player
496
+ . add_morale ( MoraleModifier :: SMALL_BONUS + player. mental . charisma / 8.0 ) ;
460
497
}
461
498
}
462
499
}
@@ -507,6 +544,7 @@ impl<'game> Game {
507
544
} else if player. tiredness > RECOVERING_TIREDNESS_PER_SHORT_TICK
508
545
&& !player. is_knocked_out ( )
509
546
{
547
+ // We don't use add_tiredness here because otherwise the stamina would have an effect.
510
548
player. tiredness -= RECOVERING_TIREDNESS_PER_SHORT_TICK ;
511
549
}
512
550
}
0 commit comments