From 83c9d657773fa4f829b533791697ed07e0d9d962 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 11 Jul 2011 19:33:27 +0000 Subject: Initial support for saving player data in multiplayer games, have ships remember their docks and spawns. --- src/game/base/ship.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/game/base/ship.cc') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index a18616e..0bc1b7c 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -38,6 +38,9 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro ship_jumpdrive_timer = 0; ship_jumpdepart = 0; + ship_dock = 0; + ship_spawn = 0; + current_impulse = false; // apply ship type settings @@ -289,6 +292,54 @@ void Ship::set_zone(core::Zone *zone) owner()->set_zone(zone); } +void Ship::set_state(int state) +{ + EntityControlable::set_state(state); + + if (state != core::Entity::Docked) + ship_dock = 0; +} +void Ship::set_dock(core::Entity *dock) +{ + if (!dock) + return; + + ship_dock = dock; + get_location().assign(dock->location()); + get_axis().assign(dock->axis()); + set_state(core::Entity::Docked); + + // if the dock is not owned by a player. set it as spawn + const core::Player *owner = (dock->type() == core::Entity::Controlable ? static_cast(dock)->owner() : 0 ); + if (!owner) + set_spawn(dock); + reset(); +} + +void Ship::launch() +{ + if (!ship_dock) + return; + + get_axis().assign(ship_dock->axis()); + + if (ship_dock->type() == core::Entity::Globe) + get_location().assign(ship_dock->location() + (ship_dock->axis().forward() * (planet_safe_distance + this->radius() + ship_dock->radius()))); + else + get_location().assign(ship_dock->location() + (ship_dock->axis().forward() * (this->radius() + ship_dock->radius()))); + + set_state(core::Entity::Normal); + + ship_dock = 0; + + reset(); +} + +void Ship::set_spawn(core::Entity *spawn) +{ + ship_spawn = spawn; +} + void Ship::action (btScalar seconds) { //float maxspeed = 0; -- cgit v1.2.3