summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/construction.rs8
-rw-r--r--src/modules/engines.rs18
-rw-r--r--src/modules/mining.rs8
-rw-r--r--src/modules/navigation.rs5
-rw-r--r--src/modules/refinery.rs6
-rw-r--r--src/modules/tractorbeam.rs9
6 files changed, 34 insertions, 20 deletions
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
index f55a2fb..20f1688 100644
--- a/src/modules/construction.rs
+++ b/src/modules/construction.rs
@@ -1,6 +1,8 @@
-use crate::modules::types::ModuleType;
use std::time::SystemTime;
+use crate::constants;
+use crate::modules::types::ModuleType;
+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ConstructionStatus {
None,
@@ -27,7 +29,7 @@ impl Construction {
Construction {
status: ConstructionStatus::None,
construction: None,
- time: 5,
+ time: constants::SHIP_CONSTRUCTION_TIME,
start: None,
}
}
@@ -58,7 +60,7 @@ impl Construction {
self.status = ConstructionStatus::None;
}
- pub fn take(&mut self) {
+ pub fn taken(&mut self) {
self.off()
}
}
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
index f319ee5..55b9af9 100644
--- a/src/modules/engines.rs
+++ b/src/modules/engines.rs
@@ -19,7 +19,13 @@ impl Engines {
acceleration
}
- pub fn give_client_data(&mut self, ship: &Mass, target: Option<&Mass>, data: String) {
+ pub fn give_client_data(
+ &mut self,
+ position: Vector,
+ velocity: Vector,
+ target: Option<&Mass>,
+ data: String,
+ ) {
let mut acceleration = Vector::default();
match data.as_bytes() {
b"5\n" => acceleration.a += 0.1,
@@ -28,21 +34,21 @@ impl Engines {
b"2\n" => acceleration.b -= 0.1,
b"4\n" => acceleration.c += 0.1,
b"6\n" => acceleration.c -= 0.1,
- b"+\n" => acceleration = ship.velocity.clone() * 0.05,
+ b"+\n" => acceleration = velocity * 0.05,
b"-\n" => {
- acceleration = ship.velocity.clone() * -1.05;
+ acceleration = velocity * -1.05;
}
b"s\n" => {
- acceleration = ship.velocity.clone() * -1.0;
+ acceleration = velocity * -1.0;
}
b"c\n" => {
if let Some(target) = target {
- acceleration = target.velocity.clone() - ship.velocity.clone();
+ acceleration = target.velocity.clone() - velocity;
}
}
b"t\n" => {
if let Some(target) = target {
- acceleration = (target.position.clone() - ship.position.clone()) * 0.01;
+ acceleration = (target.position.clone() - position) * 0.01;
}
}
_ => (),
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index b923480..1295593 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -1,5 +1,7 @@
use std::time::SystemTime;
+use crate::constants;
+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum MiningStatus {
None,
@@ -24,9 +26,9 @@ pub struct Mining {
impl Mining {
pub fn new() -> Mining {
Mining {
- range: 10.0,
+ range: constants::SHIP_MINING_RANGE,
status: MiningStatus::None,
- time: 5,
+ time: constants::SHIP_MINING_TIME,
start: None,
}
}
@@ -57,7 +59,7 @@ impl Mining {
self.status = MiningStatus::None;
}
- pub fn take(&mut self) {
+ pub fn taken(&mut self) {
self.status = MiningStatus::Mining;
}
}
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
index 03a9ca5..0e855f8 100644
--- a/src/modules/navigation.rs
+++ b/src/modules/navigation.rs
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::time::SystemTime;
+use crate::constants;
use crate::mass::Mass;
use crate::math::Vector;
@@ -30,9 +31,9 @@ impl Navigation {
pub fn new() -> Navigation {
Navigation {
target_name: None,
- range: 100.0,
+ range: constants::SHIP_NAVIGATION_RANGE,
status: NavigationStatus::None,
- time: 3,
+ time: constants::SHIP_NAVIGATION_TIME,
start: None,
}
}
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index 5fdc10c..5760306 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -1,5 +1,7 @@
use std::time::SystemTime;
+use crate::constants;
+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum RefineryStatus {
None,
@@ -23,7 +25,7 @@ pub struct Refinery {
impl Refinery {
pub fn new() -> Refinery {
Refinery {
- time: 5,
+ time: constants::SHIP_REFINERY_TIME,
start: None,
status: RefineryStatus::None,
}
@@ -55,7 +57,7 @@ impl Refinery {
self.status = RefineryStatus::None;
}
- pub fn take(&mut self) {
+ pub fn taken(&mut self) {
self.status = RefineryStatus::Refining;
}
}
diff --git a/src/modules/tractorbeam.rs b/src/modules/tractorbeam.rs
index 1ddc7d0..445b066 100644
--- a/src/modules/tractorbeam.rs
+++ b/src/modules/tractorbeam.rs
@@ -1,3 +1,4 @@
+use crate::constants;
use crate::mass::Mass;
use crate::math::Vector;
@@ -26,7 +27,7 @@ impl Tractorbeam {
pub fn new() -> Tractorbeam {
Tractorbeam {
status: TractorbeamStatus::None,
- strength: 0.1,
+ strength: constants::SHIP_TRACTORBEAM_STRENGTH,
desired_distance: None,
}
}
@@ -63,14 +64,14 @@ impl Tractorbeam {
self.status = TractorbeamStatus::None;
}
- pub fn get_acceleration(&self, ship: Mass, target: Mass) -> Vector {
- let acceleration = ship.position.clone() - target.position.clone();
+ pub fn get_acceleration(&self, position: Vector, target: Mass) -> Vector {
+ let acceleration = position.clone() - target.position.clone();
match self.status {
TractorbeamStatus::Push => acceleration.unitize() * -0.05,
TractorbeamStatus::Pull => acceleration.unitize() * 0.05,
TractorbeamStatus::Bring => match self.desired_distance {
Some(desired_distance) => {
- if desired_distance > ship.position.distance_from(target.position) {
+ if desired_distance > position.distance_from(target.position) {
acceleration.unitize() * -0.05
//some sort of velocity limiter
//if target.speed_torwards(ship) < 10.0 {