mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
orient airships correctly on load
This commit is contained in:
parent
2208a3037e
commit
3548b464da
@ -227,6 +227,7 @@ pub enum ServerEvent {
|
||||
},
|
||||
CreateShip {
|
||||
pos: Pos,
|
||||
ori: Ori,
|
||||
ship: comp::ship::Body,
|
||||
rtsim_entity: Option<RtSimVehicle>,
|
||||
driver: Option<NpcBuilder>,
|
||||
|
@ -262,6 +262,7 @@ pub enum VehicleKind {
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Vehicle {
|
||||
pub wpos: Vec3<f32>,
|
||||
pub dir: Vec2<f32>,
|
||||
|
||||
pub body: comp::ship::Body,
|
||||
|
||||
@ -283,6 +284,7 @@ impl Vehicle {
|
||||
pub fn new(wpos: Vec3<f32>, body: comp::ship::Body) -> Self {
|
||||
Self {
|
||||
wpos,
|
||||
dir: Vec2::unit_y(),
|
||||
body,
|
||||
chunk_pos: None,
|
||||
driver: None,
|
||||
|
@ -301,7 +301,6 @@ fn goto(wpos: Vec3<f32>, speed_factor: f32, goal_dist: f32) -> impl Action {
|
||||
ctx.world
|
||||
.sim()
|
||||
.get_surface_alt_approx(wpos.xy().as_())
|
||||
.map(|alt| alt)
|
||||
.unwrap_or(wpos.z),
|
||||
)
|
||||
});
|
||||
@ -314,7 +313,6 @@ fn goto(wpos: Vec3<f32>, speed_factor: f32, goal_dist: f32) -> impl Action {
|
||||
.map(|_| {})
|
||||
}
|
||||
|
||||
|
||||
fn goto_flying(
|
||||
wpos: Vec3<f32>,
|
||||
speed_factor: f32,
|
||||
@ -902,21 +900,17 @@ fn pilot(ship: common::comp::ship::Body) -> impl Action {
|
||||
})
|
||||
.choose(&mut ctx.rng);
|
||||
if let Some((_id, site)) = site {
|
||||
Either::Right(goto_2d_flying(
|
||||
site.wpos.as_(),
|
||||
1.0,
|
||||
50.0,
|
||||
150.0,
|
||||
110.0,
|
||||
ship.flying_height(),
|
||||
).then(goto_2d_flying(
|
||||
site.wpos.as_(),
|
||||
1.0,
|
||||
10.0,
|
||||
32.0,
|
||||
16.0,
|
||||
10.0,
|
||||
)))
|
||||
Either::Right(
|
||||
goto_2d_flying(
|
||||
site.wpos.as_(),
|
||||
1.0,
|
||||
50.0,
|
||||
150.0,
|
||||
110.0,
|
||||
ship.flying_height(),
|
||||
)
|
||||
.then(goto_2d_flying(site.wpos.as_(), 1.0, 10.0, 32.0, 16.0, 10.0)),
|
||||
)
|
||||
} else {
|
||||
Either::Left(finish())
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use common::{
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaChaRng;
|
||||
use tracing::{error, warn};
|
||||
use vek::Vec2;
|
||||
use world::site::SiteKind;
|
||||
|
||||
pub struct SimulateNpcs;
|
||||
@ -167,10 +168,10 @@ fn on_tick(ctx: EventCtx<SimulateNpcs, OnTick>) {
|
||||
|
||||
if dist2 > 0.5f32.powi(2) {
|
||||
let wpos = vehicle.wpos
|
||||
+ (diff
|
||||
* (vehicle.get_speed() * speed_factor * ctx.event.dt
|
||||
/ dist2.sqrt())
|
||||
.min(1.0));
|
||||
+ (diff
|
||||
* (vehicle.get_speed() * speed_factor * ctx.event.dt
|
||||
/ dist2.sqrt())
|
||||
.min(1.0));
|
||||
|
||||
let is_valid = match vehicle.body {
|
||||
common::comp::ship::Body::DefaultAirship
|
||||
@ -189,6 +190,9 @@ fn on_tick(ctx: EventCtx<SimulateNpcs, OnTick>) {
|
||||
if is_valid {
|
||||
vehicle.wpos = wpos;
|
||||
}
|
||||
vehicle.dir = (target.xy() - vehicle.wpos.xy())
|
||||
.try_normalized()
|
||||
.unwrap_or(Vec2::unit_y());
|
||||
}
|
||||
},
|
||||
// When riding, other actions are disabled
|
||||
|
@ -1572,19 +1572,14 @@ fn handle_spawn_airship(
|
||||
pos.0.z += 50.0;
|
||||
const DESTINATION_RADIUS: f32 = 2000.0;
|
||||
let angle = angle.map(|a| a * std::f32::consts::PI / 180.0);
|
||||
let destination = angle.map(|a| {
|
||||
pos.0
|
||||
+ Vec3::new(
|
||||
DESTINATION_RADIUS * a.cos(),
|
||||
DESTINATION_RADIUS * a.sin(),
|
||||
200.0,
|
||||
)
|
||||
});
|
||||
let dir = angle.map(|a| Vec3::new(a.cos(), a.sin(), 0.0));
|
||||
let destination = dir.map(|dir| pos.0 + dir * DESTINATION_RADIUS + Vec3::new(0.0, 0.0, 200.0));
|
||||
let mut rng = thread_rng();
|
||||
let ship = comp::ship::Body::random_airship_with(&mut rng);
|
||||
let ori = comp::Ori::from(common::util::Dir::new(dir.unwrap_or(Vec3::unit_y())));
|
||||
let mut builder = server
|
||||
.state
|
||||
.create_ship(pos, ship, |ship| ship.make_collider())
|
||||
.create_ship(pos, ori, ship, |ship| ship.make_collider())
|
||||
.with(LightEmitter {
|
||||
col: Rgb::new(1.0, 0.65, 0.2),
|
||||
strength: 2.0,
|
||||
@ -1621,19 +1616,14 @@ fn handle_spawn_ship(
|
||||
pos.0.z += 50.0;
|
||||
const DESTINATION_RADIUS: f32 = 2000.0;
|
||||
let angle = angle.map(|a| a * std::f32::consts::PI / 180.0);
|
||||
let destination = angle.map(|a| {
|
||||
pos.0
|
||||
+ Vec3::new(
|
||||
DESTINATION_RADIUS * a.cos(),
|
||||
DESTINATION_RADIUS * a.sin(),
|
||||
200.0,
|
||||
)
|
||||
});
|
||||
let dir = angle.map(|a| Vec3::new(a.cos(), a.sin(), 0.0));
|
||||
let destination = dir.map(|dir| pos.0 + dir * DESTINATION_RADIUS + Vec3::new(0.0, 0.0, 200.0));
|
||||
let mut rng = thread_rng();
|
||||
let ship = comp::ship::Body::random_ship_with(&mut rng);
|
||||
let ori = comp::Ori::from(common::util::Dir::new(dir.unwrap_or(Vec3::unit_y())));
|
||||
let mut builder = server
|
||||
.state
|
||||
.create_ship(pos, ship, |ship| ship.make_collider())
|
||||
.create_ship(pos, ori, ship, |ship| ship.make_collider())
|
||||
.with(LightEmitter {
|
||||
col: Rgb::new(1.0, 0.65, 0.2),
|
||||
strength: 2.0,
|
||||
@ -1683,9 +1673,12 @@ fn handle_make_volume(
|
||||
};
|
||||
server
|
||||
.state
|
||||
.create_ship(comp::Pos(pos.0 + Vec3::unit_z() * 50.0), ship, move |_| {
|
||||
collider
|
||||
})
|
||||
.create_ship(
|
||||
comp::Pos(pos.0 + Vec3::unit_z() * 50.0),
|
||||
comp::Ori::default(),
|
||||
ship,
|
||||
move |_| collider,
|
||||
)
|
||||
.build();
|
||||
|
||||
server.notify_client(
|
||||
|
@ -194,6 +194,7 @@ pub fn handle_create_npc(server: &mut Server, pos: Pos, mut npc: NpcBuilder) ->
|
||||
pub fn handle_create_ship(
|
||||
server: &mut Server,
|
||||
pos: Pos,
|
||||
ori: Ori,
|
||||
ship: comp::ship::Body,
|
||||
rtsim_vehicle: Option<RtSimVehicle>,
|
||||
driver: Option<NpcBuilder>,
|
||||
@ -201,7 +202,7 @@ pub fn handle_create_ship(
|
||||
) {
|
||||
let mut entity = server
|
||||
.state
|
||||
.create_ship(pos, ship, |ship| ship.make_collider());
|
||||
.create_ship(pos, ori, ship, |ship| ship.make_collider());
|
||||
/*
|
||||
if let Some(mut agent) = agent {
|
||||
let (kp, ki, kd) = pid_coefficients(&Body::Ship(ship));
|
||||
|
@ -193,10 +193,11 @@ impl Server {
|
||||
},
|
||||
ServerEvent::CreateShip {
|
||||
pos,
|
||||
ori,
|
||||
ship,
|
||||
rtsim_entity,
|
||||
driver,
|
||||
} => handle_create_ship(self, pos, ship, rtsim_entity, driver, Vec::new()),
|
||||
} => handle_create_ship(self, pos, ori, ship, rtsim_entity, driver, Vec::new()),
|
||||
ServerEvent::CreateWaypoint(pos) => handle_create_waypoint(self, pos),
|
||||
ServerEvent::ClientDisconnect(entity, reason) => {
|
||||
frontend_events.push(handle_client_disconnect(self, entity, reason, false))
|
||||
|
@ -11,6 +11,7 @@ use common::{
|
||||
slowjob::SlowJobPool,
|
||||
terrain::CoordinateConversions,
|
||||
trade::{Good, SiteInformation},
|
||||
util::Dir,
|
||||
LoadoutBuilder,
|
||||
};
|
||||
use common_ecs::{Job, Origin, Phase, System};
|
||||
@ -315,6 +316,7 @@ impl<'a> System<'a> for Sys {
|
||||
|
||||
emitter.emit(ServerEvent::CreateShip {
|
||||
pos: comp::Pos(vehicle.wpos),
|
||||
ori: comp::Ori::from(Dir::new(vehicle.dir.with_z(0.0))),
|
||||
ship: vehicle.body,
|
||||
rtsim_entity: Some(RtSimVehicle(vehicle_id)),
|
||||
driver: vehicle.driver.and_then(&mut actor_info),
|
||||
|
@ -64,6 +64,7 @@ pub trait StateExt {
|
||||
fn create_ship<F: FnOnce(comp::ship::Body) -> comp::Collider>(
|
||||
&mut self,
|
||||
pos: comp::Pos,
|
||||
ori: comp::Ori,
|
||||
ship: comp::ship::Body,
|
||||
make_collider: F,
|
||||
) -> EcsEntityBuilder;
|
||||
@ -338,6 +339,7 @@ impl StateExt for State {
|
||||
fn create_ship<F: FnOnce(comp::ship::Body) -> comp::Collider>(
|
||||
&mut self,
|
||||
pos: comp::Pos,
|
||||
ori: comp::Ori,
|
||||
ship: comp::ship::Body,
|
||||
make_collider: F,
|
||||
) -> EcsEntityBuilder {
|
||||
@ -347,7 +349,7 @@ impl StateExt for State {
|
||||
.create_entity_synced()
|
||||
.with(pos)
|
||||
.with(comp::Vel(Vec3::zero()))
|
||||
.with(comp::Ori::default())
|
||||
.with(ori)
|
||||
.with(body.mass())
|
||||
.with(body.density())
|
||||
.with(make_collider(ship))
|
||||
|
Loading…
Reference in New Issue
Block a user