1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
//! The command-post link to a friendly warbot's cockpit.
use super::{has_working_pilot_control, start_warbot_control};
use crate::{
component_cockpit,
strategic_roster::warbot_rows,
strategic_view::{command_post, CommandPost},
Engine, StartingCockpit,
};
use fparkan_world::{identity_metadata, ObjectHandle};
fn remote_cockpit(
engine: &Engine,
hero: StartingCockpit,
target: ObjectHandle,
) -> Option<StartingCockpit> {
let mission = engine.loaded.as_ref()?;
if mission.boarding.is_some()
|| !matches!(command_post(engine, hero), Some(CommandPost::Bunker(_)))
|| !warbot_rows(engine, hero)
.iter()
.any(|row| row.handle == target && row.selectable)
|| mission
.unit_patrol
.as_ref()
.is_some_and(|patrol| patrol.is_leaving_factory(target))
{
return None;
}
let table = mission
.control_device_tables
.iter()
.find(|table| table.handle == target)?;
if !has_working_pilot_control(table) {
return None;
}
let id = identity_metadata(&engine.world, target).ok()?.original_id?;
component_cockpit(mission, id.0 as usize, target)
}
/// Whether the selected friendly warbot has a usable manual-control cockpit.
#[must_use]
pub fn can_control_warbot_remotely(
engine: &Engine,
hero: StartingCockpit,
target: ObjectHandle,
) -> bool {
remote_cockpit(engine, hero, target).is_some()
}
/// Gives the hero manual control of a warbot while the hero remains at the bunker.
pub fn control_warbot_remotely(
engine: &mut Engine,
hero: StartingCockpit,
target: ObjectHandle,
) -> Option<StartingCockpit> {
let cockpit = remote_cockpit(engine, hero, target)?;
if let Some(patrol) = engine.loaded.as_mut()?.unit_patrol.as_mut() {
patrol.release_orders_for_manual_control(target);
}
start_warbot_control(engine, hero, cockpit, true);
Some(cockpit)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
create, disembark_warbot, frame_with_player_motion, load_gameplay_mission,
plan_player_motion, starting_cockpit, strategic_orders, EngineServices, MissionMode,
MissionRequest, MissionStartupInput, PlayerMotion,
};
use fparkan_vfs::DirectoryVfs;
use fparkan_world::transform_state;
use std::sync::Arc;
#[test]
#[ignore = "requires licensed corpus"]
fn licensed_fortresses_drives_the_warbot_without_moving_the_hero() {
let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus");
let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
load_gameplay_mission(
&mut engine,
MissionRequest {
key: "MISSIONS/Single.01/data.tma".into(),
mode: MissionMode::SingleMission,
},
MissionStartupInput {
queue_time_ms: 0,
research_creation_gate: false,
},
None,
)
.unwrap();
let hero = starting_cockpit(&engine).unwrap();
let actor = warbot_rows(&engine, hero)[0].handle;
let hero_pose = transform_state(&engine.world, hero.handle).unwrap();
let vehicle_pose = transform_state(&engine.world, actor).unwrap();
assert!(crate::boarding::vehicle_interaction_distance_sq(
hero_pose.position.map(f32::from_bits),
vehicle_pose.position.map(f32::from_bits)
)
.is_none());
assert!(strategic_orders::stand(&mut engine, hero, actor));
let vehicle = control_warbot_remotely(&mut engine, hero, actor).unwrap();
assert_eq!(vehicle.handle, actor);
assert_eq!(warbot_rows(&engine, hero)[0].order_label, 0x1824);
for time in [100, 200, 300, 400, 500] {
let motion = plan_player_motion(
&engine,
vehicle,
PlayerMotion {
movement: [0.0, 1.0],
delta_seconds: 0.1,
..PlayerMotion::default()
},
)
.unwrap()
.unwrap();
frame_with_player_motion(&mut engine, time, vehicle, motion, false).unwrap();
}
assert_ne!(
transform_state(&engine.world, actor).unwrap().position,
vehicle_pose.position
);
assert_eq!(
transform_state(&engine.world, hero.handle).unwrap(),
hero_pose
);
assert_eq!(disembark_warbot(&mut engine).unwrap(), Some(hero));
assert_eq!(
transform_state(&engine.world, hero.handle).unwrap(),
hero_pose
);
assert!(crate::player_vehicle(&engine).is_none());
}
}
|