Skip to content

Commit

Permalink
tweak constant names, minor comment cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Aug 27, 2024
1 parent d780c67 commit bde9a50
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/constants/seasonal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,63 +42,66 @@ pub mod season_1 {

// extra constants for s1 related to the score spawn bonus/crisis cycle
// https://github.com/screeps/mod-season1/blob/7ca3c7ddb47bf9dfbdfb4e72b666a3159fde8780/src/scoreContainer.roomObject.js
/// The duration of a full score cycle
/// The duration of a full score cycle.
pub const SCORE_CYCLE_DURATION: u32 = 50_000;

/// The point of the score cycle where bonus time begins, multiplying
/// spawned score by [`SCORE_BONUS_MULTIPLIER`].
pub const SCORE_BONUS_START: u32 = 45_000;
/// spawned score by [`SCORE_CYCLE_BONUS_MULTIPLIER`].
pub const SCORE_CYCLE_BONUS_START: u32 = 45_000;

/// The point of the score cycle where bonus time ends
pub const SCORE_BONUS_END: u32 = 50_000;
/// The point of the score cycle where bonus time ends.
pub const SCORE_CYCLE_BONUS_END: u32 = 50_000;

/// The multiplier for score spawned during bonus time
pub const SCORE_BONUS_MULTIPLIER: u8 = 2;
/// The multiplier for score spawned during bonus time.
pub const SCORE_CYCLE_BONUS_MULTIPLIER: u8 = 2;

/// The point of the score cycle where crisis time begins, during which no
/// new [`ScoreContainer`]s will be spawned.
///
/// [`ScoreContainer`]: crate::objects::ScoreContainer
pub const SCORE_CRISIS_START: u32 = 10_000;
pub const SCORE_CYCLE_CRISIS_START: u32 = 10_000;

/// The point of the score cycle where crisis time ends, allowing
/// [`ScoreContainer`]s to be spawned once again.
///
/// [`ScoreContainer`]: crate::objects::ScoreContainer
pub const SCORE_CRISIS_END: u32 = 15_000;
pub const SCORE_CYCLE_CRISIS_END: u32 = 15_000;

/// The multiplier for score spawned during crisis time
pub const SCORE_CRISIS_MULTIPLIER: u8 = 0;
/// The multiplier for score spawned during crisis time.
pub const SCORE_CYCLE_CRISIS_MULTIPLIER: u8 = 0;

/// The minimum amount of ticks a [`ScoreContainer`] can exist before
/// despawning
/// despawning.
///
/// [`ScoreContainer`]: crate::objects::ScoreContainer
// https://github.com/screeps/mod-season1/blob/7ca3c7ddb47bf9dfbdfb4e72b666a3159fde8780/src/scoreContainer.roomObject.js#L93
pub const SCORE_MIN_DECAY: u16 = 500;

/// The maximum amount of ticks a [`ScoreContainer`] can exist before
/// despawning
/// despawning.
///
/// [`ScoreContainer`]: crate::objects::ScoreContainer
pub const SCORE_MAX_DECAY: u16 = 5_000;

/// The different parts of the score cycle
/// The different periods in the score cycle.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ScoreCycleState {
/// Normal score spawns during the normal parts of the cycle
Normal,
/// No score spawns during the crisis period
Crisis,
/// Double score in each container during the bonus period
Bonus,
}

impl ScoreCycleState {
/// Gets the multiplier of score associated with the represented part of
/// the score cycle
/// the score cycle.
pub fn multiplier(&self) -> u8 {
match self {
ScoreCycleState::Normal => 1,
ScoreCycleState::Crisis => SCORE_CRISIS_MULTIPLIER,
ScoreCycleState::Bonus => SCORE_BONUS_MULTIPLIER,
ScoreCycleState::Crisis => SCORE_CYCLE_CRISIS_MULTIPLIER,
ScoreCycleState::Bonus => SCORE_CYCLE_BONUS_MULTIPLIER,
}
}
}
Expand All @@ -108,11 +111,11 @@ pub mod season_1 {
// the bonus/crisis periods are exclusive of their boundaries
// https://github.com/screeps/mod-season1/blob/7ca3c7ddb47bf9dfbdfb4e72b666a3159fde8780/src/scoreContainer.roomObject.js#L77-L81
// match on those exact values first
SCORE_CRISIS_START => ScoreCycleState::Normal,
SCORE_BONUS_START => ScoreCycleState::Normal,
SCORE_CYCLE_CRISIS_START => ScoreCycleState::Normal,
SCORE_CYCLE_BONUS_START => ScoreCycleState::Normal,
// then on the remaining ranges
SCORE_CRISIS_START..SCORE_CRISIS_END => ScoreCycleState::Crisis,
SCORE_BONUS_START..SCORE_BONUS_END => ScoreCycleState::Bonus,
SCORE_CYCLE_CRISIS_START..SCORE_CYCLE_CRISIS_END => ScoreCycleState::Crisis,
SCORE_CYCLE_BONUS_START..SCORE_CYCLE_BONUS_END => ScoreCycleState::Bonus,
_ => ScoreCycleState::Normal,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/local/room_xy/extra_math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl RoomXY {
/// pos.offset(-5, 5);
/// assert_eq!(pos, RoomXY::checked_new(16, 26).unwrap());
/// ```
///
/// [`Position::offset`]: crate::local::Position::offset
#[inline]
#[track_caller]
pub fn offset(&mut self, x: i8, y: i8) {
Expand Down

0 comments on commit bde9a50

Please sign in to comment.