summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-20 13:09:11 -0600
committertom barrett <spalf0@gmail.com>2019-02-20 13:09:11 -0600
commitc6be289134c1f749884d269f955b39d39b604469 (patch)
treef28411c2c3215e757c8e89acc2eb7eae308f97da /src/modules
parentadab367eb1590f78c89806335e46fb689b9719ee (diff)
new naming scheme
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/construction.rs26
-rw-r--r--src/modules/engines.rs10
-rw-r--r--src/modules/mining.rs28
-rw-r--r--src/modules/navigation.rs22
-rw-r--r--src/modules/refinery.rs28
-rw-r--r--src/modules/tractorbeam.rs48
6 files changed, 81 insertions, 81 deletions
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
index ca4dd2d..0eec155 100644
--- a/src/modules/construction.rs
+++ b/src/modules/construction.rs
@@ -10,7 +10,7 @@ use crate::storage::Storage;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Construction {
- pub status: ConstructionStatus,
+ pub status: Status,
construction: Option<ModuleType>,
time: u64,
start: Option<SystemTime>,
@@ -19,7 +19,7 @@ pub struct Construction {
impl Construction {
pub fn new() -> Construction {
Construction {
- status: ConstructionStatus::None,
+ status: Status::None,
construction: None,
time: constants::SHIP_CONSTRUCTION_TIME,
start: None,
@@ -39,10 +39,10 @@ impl Construction {
if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.start = Some(SystemTime::now());
- self.status = ConstructionStatus::Constructed;
+ self.status = Status::Constructed;
}
}
- if self.status == ConstructionStatus::Constructed {
+ if self.status == Status::Constructed {
storage
.take_items(ItemType::Iron, constants::SHIP_CONSTRUCTION_IRON_COST)
.unwrap();
@@ -59,7 +59,7 @@ impl Construction {
}
pub fn get_client_data(&self, storage: &Storage) -> String {
- let client_data = ConstructionClientData {
+ let client_data = ClientData {
has_enough: self.has_enough(storage),
status: self.status.clone(),
};
@@ -83,19 +83,19 @@ impl Construction {
fn toggle(&mut self) {
match self.status {
- ConstructionStatus::None => self.on(),
+ Status::None => self.on(),
_ => self.off(),
};
}
fn on(&mut self) {
self.start = Some(SystemTime::now());
- self.status = ConstructionStatus::Constructing;
+ self.status = Status::Constructing;
}
fn off(&mut self) {
self.start = None;
- self.status = ConstructionStatus::None;
+ self.status = Status::None;
}
fn constructed(&mut self) {
@@ -104,20 +104,20 @@ impl Construction {
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct ConstructionClientData {
- pub status: ConstructionStatus,
+pub struct ClientData {
+ pub status: Status,
pub has_enough: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum ConstructionStatus {
+pub enum Status {
None,
Constructing,
Constructed,
}
-impl Default for ConstructionStatus {
+impl Default for Status {
fn default() -> Self {
- ConstructionStatus::None
+ Status::None
}
}
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
index 63e1fcd..313346a 100644
--- a/src/modules/engines.rs
+++ b/src/modules/engines.rs
@@ -1,7 +1,7 @@
use crate::constants;
use crate::mass::Mass;
use crate::math::Vector;
-use crate::modules::navigation::NavigationStatus;
+use crate::modules::navigation;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Engines {
@@ -62,9 +62,9 @@ impl Engines {
self.acceleration = acceleration;
}
- pub fn get_client_data(&self, status: NavigationStatus) -> String {
- let client_data = EnginesClientData {
- has_target: status == NavigationStatus::Targeted,
+ pub fn get_client_data(&self, status: navigation::Status) -> String {
+ let client_data = ClientData {
+ has_target: status == navigation::Status::Targeted,
fuel: self.fuel,
};
serde_json::to_string(&client_data).unwrap() + "\n"
@@ -87,7 +87,7 @@ impl Engines {
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct EnginesClientData {
+pub struct ClientData {
pub has_target: bool,
pub fuel: f64,
}
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index 8e5b001..816313e 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -10,7 +10,7 @@ use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Mining {
pub range: f64,
- pub status: MiningStatus,
+ pub status: Status,
time: u64,
start: Option<SystemTime>,
}
@@ -19,7 +19,7 @@ impl Mining {
pub fn new() -> Mining {
Mining {
range: constants::SHIP_MINING_RANGE,
- status: MiningStatus::None,
+ status: Status::None,
time: constants::SHIP_MINING_TIME,
start: None,
}
@@ -37,11 +37,11 @@ impl Mining {
}
if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = MiningStatus::Mined;
+ self.status = Status::Mined;
self.start = None;
}
}
- if self.status == MiningStatus::Mined {
+ if self.status == Status::Mined {
if let MassType::Astroid {
ref mut resources, ..
} = target.mass_type
@@ -89,7 +89,7 @@ impl Mining {
None => false,
};
- let client_data = MiningClientData {
+ let client_data = ClientData {
has_astroid_target,
astroid_has_minerals,
is_within_range,
@@ -102,45 +102,45 @@ impl Mining {
fn toggle(&mut self) {
match self.status {
- MiningStatus::None => self.on(),
+ Status::None => self.on(),
_ => self.off(),
};
}
fn on(&mut self) {
self.start = Some(SystemTime::now());
- self.status = MiningStatus::Mining;
+ self.status = Status::Mining;
}
fn off(&mut self) {
self.start = None;
- self.status = MiningStatus::None;
+ self.status = Status::None;
}
fn mined(&mut self) {
- self.status = MiningStatus::Mining;
+ self.status = Status::Mining;
self.start = Some(SystemTime::now());
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct MiningClientData {
+pub struct ClientData {
pub has_astroid_target: bool,
pub astroid_has_minerals: bool,
pub is_within_range: bool,
- pub status: MiningStatus,
+ pub status: Status,
pub range: f64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum MiningStatus {
+pub enum Status {
None,
Mining,
Mined,
}
-impl Default for MiningStatus {
+impl Default for Status {
fn default() -> Self {
- MiningStatus::None
+ Status::None
}
}
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
index b15beef..c931338 100644
--- a/src/modules/navigation.rs
+++ b/src/modules/navigation.rs
@@ -8,7 +8,7 @@ use crate::math::Vector;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Navigation {
pub range: f64,
- pub status: NavigationStatus,
+ pub status: Status,
pub target_name: Option<String>,
time: u64,
start: Option<SystemTime>,
@@ -19,7 +19,7 @@ impl Navigation {
Navigation {
target_name: None,
range: constants::SHIP_NAVIGATION_RANGE,
- status: NavigationStatus::None,
+ status: Status::None,
time: constants::SHIP_NAVIGATION_TIME,
start: None,
}
@@ -29,7 +29,7 @@ impl Navigation {
self.verify_target(ship_position, masses);
if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = NavigationStatus::Targeted;
+ self.status = Status::Targeted;
self.start = None;
}
}
@@ -38,13 +38,13 @@ impl Navigation {
pub fn give_received_data(&mut self, recv: String) {
if !recv.is_empty() {
self.start = Some(SystemTime::now());
- self.status = NavigationStatus::Targeting;
+ self.status = Status::Targeting;
self.target_name = Some(recv);
}
}
pub fn get_client_data(&self, ship_position: Vector, masses: &HashMap<String, Mass>) -> String {
- let client_data = NavigationClientData {
+ let client_data = ClientData {
ship_position: ship_position.clone(),
status: self.status.clone(),
target_name: self.target_name.clone(),
@@ -63,29 +63,29 @@ impl Navigation {
let target = masses.get(&name).unwrap();
if target.position.distance_from(ship_position) > self.range {
self.target_name = None;
- self.status = NavigationStatus::None;
+ self.status = Status::None;
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct NavigationClientData {
+pub struct ClientData {
pub ship_position: Vector,
pub available_targets: Vec<(String, Vector)>,
- pub status: NavigationStatus,
+ pub status: Status,
pub target_name: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum NavigationStatus {
+pub enum Status {
None,
Targeting,
Targeted,
}
-impl Default for NavigationStatus {
+impl Default for Status {
fn default() -> Self {
- NavigationStatus::None
+ Status::None
}
}
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index a0a401b..0e5e125 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -8,7 +8,7 @@ use crate::storage::Storage;
pub struct Refinery {
time: u64,
start: Option<SystemTime>,
- pub status: RefineryStatus,
+ pub status: Status,
}
impl Refinery {
@@ -16,7 +16,7 @@ impl Refinery {
Refinery {
time: constants::SHIP_REFINERY_TIME,
start: None,
- status: RefineryStatus::None,
+ status: Status::None,
}
}
@@ -26,11 +26,11 @@ impl Refinery {
}
if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
- self.status = RefineryStatus::Refined;
+ self.status = Status::Refined;
self.start = None
}
}
- if self.status == RefineryStatus::Refined {
+ if self.status == Status::Refined {
storage.take_item(ItemType::CrudeMinerals);
storage.give_item(Item::new(ItemType::Iron));
storage.give_item(Item::new(ItemType::Hydrogen));
@@ -39,7 +39,7 @@ impl Refinery {
}
pub fn get_client_data(&self, storage: &Storage) -> String {
- let client_data = RefineryClientData {
+ let client_data = ClientData {
has_crude_minerals: self.has_crude_minerals(storage),
status: self.status.clone(),
};
@@ -62,42 +62,42 @@ impl Refinery {
fn toggle(&mut self) {
match self.status {
- RefineryStatus::None => self.on(),
+ Status::None => self.on(),
_ => self.off(),
};
}
fn on(&mut self) {
self.start = Some(SystemTime::now());
- self.status = RefineryStatus::Refining;
+ self.status = Status::Refining;
}
fn off(&mut self) {
self.start = None;
- self.status = RefineryStatus::None;
+ self.status = Status::None;
}
fn taken(&mut self) {
- self.status = RefineryStatus::Refining;
+ self.status = Status::Refining;
self.start = Some(SystemTime::now());
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct RefineryClientData {
+pub struct ClientData {
pub has_crude_minerals: bool,
- pub status: RefineryStatus,
+ pub status: Status,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
-pub enum RefineryStatus {
+pub enum Status {
None,
Refining,
Refined,
}
-impl Default for RefineryStatus {
+impl Default for Status {
fn default() -> Self {
- RefineryStatus::None
+ Status::None
}
}
diff --git a/src/modules/tractorbeam.rs b/src/modules/tractorbeam.rs
index 3bbb32a..4f91292 100644
--- a/src/modules/tractorbeam.rs
+++ b/src/modules/tractorbeam.rs
@@ -4,7 +4,7 @@ use crate::math::Vector;
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Tractorbeam {
- pub status: TractorbeamStatus,
+ pub status: Status,
strength: f64,
desired_distance: Option<f64>,
}
@@ -12,7 +12,7 @@ pub struct Tractorbeam {
impl Tractorbeam {
pub fn new() -> Tractorbeam {
Tractorbeam {
- status: TractorbeamStatus::None,
+ status: Status::None,
strength: constants::SHIP_TRACTORBEAM_STRENGTH,
desired_distance: None,
}
@@ -21,7 +21,7 @@ impl Tractorbeam {
pub fn process(&mut self) {}
pub fn get_client_data(&self, target: Option<&Mass>) -> String {
- let client_data = TractorbeamClientData {
+ let client_data = ClientData {
has_target: target.is_some(),
status: self.status.clone(),
};
@@ -41,9 +41,9 @@ impl Tractorbeam {
pub fn get_acceleration(&self, ship_position: Vector, target_position: Vector) -> Vector {
let acceleration = ship_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 {
+ Status::Push => acceleration.unitize() * -0.05,
+ Status::Pull => acceleration.unitize() * 0.05,
+ Status::Bring => match self.desired_distance {
Some(desired_distance) => {
if desired_distance > ship_position.distance_from(target_position) {
acceleration.unitize() * -0.05
@@ -59,55 +59,55 @@ impl Tractorbeam {
}
None => Vector::default(),
},
- TractorbeamStatus::None => Vector::default(),
+ Status::None => Vector::default(),
}
}
fn toggle_pull(&mut self) {
self.status = match self.status {
- TractorbeamStatus::None => TractorbeamStatus::Pull,
- TractorbeamStatus::Push => TractorbeamStatus::Pull,
- TractorbeamStatus::Bring => TractorbeamStatus::Pull,
- TractorbeamStatus::Pull => TractorbeamStatus::None,
+ Status::None => Status::Pull,
+ Status::Push => Status::Pull,
+ Status::Bring => Status::Pull,
+ Status::Pull => Status::None,
}
}
fn toggle_push(&mut self) {
self.status = match self.status {
- TractorbeamStatus::None => TractorbeamStatus::Push,
- TractorbeamStatus::Pull => TractorbeamStatus::Push,
- TractorbeamStatus::Bring => TractorbeamStatus::Push,
- TractorbeamStatus::Push => TractorbeamStatus::None,
+ Status::None => Status::Push,
+ Status::Pull => Status::Push,
+ Status::Bring => Status::Push,
+ Status::Push => Status::None,
}
}
fn toggle_bring(&mut self, desired_distance: f64) {
self.desired_distance = Some(desired_distance);
self.status = match self.status {
- TractorbeamStatus::None => TractorbeamStatus::Bring,
- TractorbeamStatus::Pull => TractorbeamStatus::Bring,
- TractorbeamStatus::Push => TractorbeamStatus::Bring,
- TractorbeamStatus::Bring => TractorbeamStatus::None,
+ Status::None => Status::Bring,
+ Status::Pull => Status::Bring,
+ Status::Push => Status::Bring,
+ Status::Bring => Status::None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub struct TractorbeamClientData {
+pub struct ClientData {
pub has_target: bool,
- pub status: TractorbeamStatus,
+ pub status: Status,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
-pub enum TractorbeamStatus {
+pub enum Status {
None,
Push,
Pull,
Bring,
}
-impl Default for TractorbeamStatus {
+impl Default for Status {
fn default() -> Self {
- TractorbeamStatus::None
+ Status::None
}
}