Skip to content

Commit 8bf625a

Browse files
Dmytro Lysaipingw33n
authored andcommitted
[game] Call Use for other obj types
1 parent 04784f0 commit 8bf625a

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/asset/proto.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use crate::util::{enum_iter, EnumIter};
1818
/// "The doorway seems to be blocked."
1919
pub const MSG_DOORWAY_SEEMS_TO_BE_BLOCKED: MessageId = 597;
2020

21+
/// "You see: %s."
22+
pub const MSG_YOU_SEE_X: MessageId = 480;
23+
2124
#[derive(Debug)]
2225
pub struct Proto {
2326
id: ProtoId,

src/game/state.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,20 +688,59 @@ impl GameState {
688688
// return 0;
689689
// }
690690

691-
let used_kind = {
691+
let (used_kind, script) = {
692692
let world = self.world.borrow();
693693
let usedo = world.objects().get(used);
694-
if let Some(ExactEntityKind::Scenery(v)) = usedo.proto().map(|p| p.kind()) {
695-
v
696-
} else {
697-
return;
698-
}
694+
let used_kind = unwrap_or_return!(
695+
usedo.proto().map(|p| p.kind()),
696+
Some(ExactEntityKind::Scenery(v)) => v);
697+
(used_kind, usedo.script)
699698
};
700699

701700
if used_kind == SceneryKind::Door {
702701
self.use_door(user, used, ui);
703702
} else {
704-
// TODO
703+
let world = &mut self.world.borrow_mut();
704+
705+
let script_overrides = if let Some((sid, _)) = script {
706+
self.scripts.execute_predefined_proc(sid, PredefinedProc::Use,
707+
&mut script::Context {
708+
world,
709+
sequencer: &mut self.sequencer,
710+
dialog: &mut self.dialog,
711+
ui,
712+
message_panel: self.message_panel,
713+
map_id: self.map_id.unwrap(),
714+
source_obj: Some(user),
715+
target_obj: Some(used),
716+
}).unwrap().assert_no_suspend().script_overrides
717+
} else {
718+
false
719+
};
720+
let script_overrides = if !script_overrides {
721+
match used_kind {
722+
SceneryKind::Door => unreachable!(),
723+
// TODO
724+
| SceneryKind::Stairs
725+
| SceneryKind::Elevator
726+
| SceneryKind::LadderDown
727+
| SceneryKind::LadderUp
728+
=> {
729+
warn!("{:?} use is not implemented", used_kind);
730+
false
731+
}
732+
SceneryKind::Misc => false,
733+
}
734+
} else {
735+
false
736+
};
737+
if !script_overrides && user == world.dude_obj().unwrap() {
738+
if let Some(obj_name) = world.object_name(used) {
739+
let msg = &self.proto_db.messages().get(MSG_YOU_SEE_X).unwrap().text;
740+
let msg = sprintf(msg, &[&obj_name]);
741+
self.push_message(&msg, ui);
742+
}
743+
}
705744
}
706745
}
707746

src/macros.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@ macro_rules! enum_len {
33
($ty:ty) => {{
44
<$ty as ::enum_map::Enum<()>>::POSSIBLE_VALUES
55
}};
6+
}
7+
8+
macro_rules! unwrap_or_return {
9+
($expression:expr, $pattern:pat => $res:expr) => {
10+
match $expression {
11+
$pattern => $res,
12+
_ => return,
13+
}
14+
}
615
}

0 commit comments

Comments
 (0)