Skip to content

Commit

Permalink
restore the commute challenges [rebuild]
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Apr 26, 2020
1 parent 94a5678 commit 7791835
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
14 changes: 10 additions & 4 deletions game/src/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Challenge {
pub description: Vec<String>,
pub alias: String,
pub gameplay: GameplayMode,
pub cutscene: Option<fn(&mut EventCtx, &App) -> Box<dyn State>>,
pub cutscene: Option<fn(&mut EventCtx, &App, &GameplayMode) -> Box<dyn State>>,
}

// TODO Assuming the measurement is always maximizing time savings from a goal.
Expand All @@ -35,7 +35,7 @@ impl Challenge {
title: "Part 1".to_string(),
description: vec!["Speed up one VIP's daily commute, at any cost!".to_string()],
alias: "commute/pt1".to_string(),
gameplay: GameplayMode::OptimizeCommute(PersonID(1163), Duration::minutes(2)),
gameplay: GameplayMode::OptimizeCommute(PersonID(8819), Duration::minutes(2)),
cutscene: Some(
crate::sandbox::gameplay::commute::OptimizeCommute::cutscene_pt1,
),
Expand All @@ -44,7 +44,10 @@ impl Challenge {
title: "Part 2".to_string(),
description: vec!["Speed up another VIP's commute".to_string()],
alias: "commute/pt2".to_string(),
gameplay: GameplayMode::OptimizeCommute(PersonID(3434), Duration::minutes(5)),
gameplay: GameplayMode::OptimizeCommute(
PersonID(13121),
Duration::seconds(90.0),
),
cutscene: Some(
crate::sandbox::gameplay::commute::OptimizeCommute::cutscene_pt2,
),
Expand Down Expand Up @@ -266,7 +269,10 @@ impl Tab {
Box::new(move |ctx, app| {
let sandbox = Box::new(SandboxMode::new(ctx, app, challenge.gameplay.clone()));
if let Some(cutscene) = challenge.cutscene {
Some(Transition::ReplaceThenPush(sandbox, cutscene(ctx, app)))
Some(Transition::ReplaceThenPush(
sandbox,
cutscene(ctx, app, &challenge.gameplay),
))
} else {
Some(Transition::Replace(sandbox))
}
Expand Down
4 changes: 2 additions & 2 deletions game/src/cutscene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ impl CutsceneBuilder {
CutsceneBuilder { scenes: Vec::new() }
}

pub fn scene(mut self, avatar: &str, msg: &str) -> CutsceneBuilder {
pub fn scene<I: Into<String>>(mut self, avatar: &str, msg: I) -> CutsceneBuilder {
self.scenes.push(Scene {
avatar: Some(avatar.to_string()),
msg: Text::from(Line(msg)),
});
self
}

pub fn narrator(mut self, msg: &str) -> CutsceneBuilder {
pub fn narrator<I: Into<String>>(mut self, msg: I) -> CutsceneBuilder {
self.scenes.push(Scene {
avatar: None,
msg: Text::from(Line(msg)),
Expand Down
33 changes: 23 additions & 10 deletions game/src/sandbox/gameplay/commute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ impl OptimizeCommute {
})
}

pub fn cutscene_pt1(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
pub fn cutscene_pt1(ctx: &mut EventCtx, app: &App, mode: &GameplayMode) -> Box<dyn State> {
let goal = match mode {
GameplayMode::OptimizeCommute(_, d) => *d,
_ => unreachable!(),
};
CutsceneBuilder::new()
.scene("boss", "Listen up, I've got a special job for you today.")
.scene(
Expand Down Expand Up @@ -94,14 +98,20 @@ impl OptimizeCommute {
"The drone has been programmed to find the anonymous VIP. Watch their daily \
route, figure out what's wrong, and fix it.",
)
.narrator(
.narrator(format!(
"Ignore the damage done to everyone else. Just speed up the VIP's trips by a \
total of 2 minutes.",
)
total of {}.",
goal
))
.build(ctx, app)
}

pub fn cutscene_pt2(ctx: &mut EventCtx, app: &App) -> Box<dyn State> {
pub fn cutscene_pt2(ctx: &mut EventCtx, app: &App, mode: &GameplayMode) -> Box<dyn State> {
let goal = match mode {
GameplayMode::OptimizeCommute(_, d) => *d,
_ => unreachable!(),
};
// TODO The person chosen for this currently has more of an issue needing PBLs, actually.
CutsceneBuilder::new()
.scene(
"boss",
Expand All @@ -127,10 +137,11 @@ impl OptimizeCommute {
"Everyone's calling in favors these days. Just make it happen!",
)
.narrator("Too many people have dirt on the boss. Guess we have another VIP to help.")
.narrator(
.narrator(format!(
"Once again, ignore the damage to everyone else, and just speed up the VIP's \
trips by a total of 5 minutes.",
)
trips by a total of {}.",
goal
))
.build(ctx, app)
}
}
Expand Down Expand Up @@ -196,7 +207,9 @@ impl GameplayState for OptimizeCommute {
.0
.cutscene
.unwrap())(
ctx, app
ctx,
app,
&GameplayMode::OptimizeCommute(self.person, self.goal),
))),
false,
);
Expand Down Expand Up @@ -416,7 +429,7 @@ impl State for FinalScore {
(Challenge::find(self.next_mode.as_ref().unwrap())
.0
.cutscene
.unwrap())(ctx, app),
.unwrap())(ctx, app, self.next_mode.as_ref().unwrap()),
]),
"Back to challenges" => {
Transition::Clear(vec![main_menu(ctx, app), challenges_picker(ctx, app)])
Expand Down
3 changes: 2 additions & 1 deletion sim/src/trips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ impl TripManager {
if self.active_trip_mode.get(&a) == Some(&id) {
TripResult::Ok(a)
} else {
panic!("{} should be ongoing, but no agent in active_trip_mode", id);
//panic!("{} should be ongoing, but no agent in active_trip_mode", id);
TripResult::ModeChange
}
}

Expand Down

0 comments on commit 7791835

Please sign in to comment.