summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
committertom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
commit46fa862e04bc43311ba79ef3db70abf9014b9104 (patch)
tree3507873ec788af1f1e0885bbb676dbb4a373d48e
parent828f0d83dcb258a8e5efd55a7775592c6e5f77bc (diff)
bringing to 2018
-rw-r--r--.clippy.toml1
-rw-r--r--Cargo.lock251
-rw-r--r--Cargo.toml5
-rw-r--r--src/bin/client.rs39
-rw-r--r--src/bin/server.rs28
-rw-r--r--src/client/construction.rs57
-rw-r--r--src/client/dashboard.rs28
-rw-r--r--src/client/engines.rs38
-rw-r--r--src/client/mining.rs52
-rw-r--r--src/client/mod.rs8
-rw-r--r--src/client/navigation.rs71
-rw-r--r--src/client/refinery.rs39
-rw-r--r--src/item.rs17
-rw-r--r--src/lib.rs6
-rw-r--r--src/mass.rs168
-rw-r--r--src/math.rs11
-rw-r--r--src/modules/construction.rs28
-rw-r--r--src/modules/dashboard.rs2
-rw-r--r--src/modules/engines.rs66
-rw-r--r--src/modules/mining.rs26
-rw-r--r--src/modules/mod.rs10
-rw-r--r--src/modules/navigation.rs44
-rw-r--r--src/modules/refinery.rs22
-rw-r--r--src/server/connection.rs44
-rw-r--r--src/server/construction.rs71
-rw-r--r--src/server/dashboard.rs8
-rw-r--r--src/server/engines.rs19
-rw-r--r--src/server/mining.rs102
-rw-r--r--src/server/mod.rs10
-rw-r--r--src/server/navigation.rs28
-rw-r--r--src/server/refinery.rs46
-rw-r--r--src/storage.rs38
32 files changed, 818 insertions, 565 deletions
diff --git a/.clippy.toml b/.clippy.toml
new file mode 100644
index 0000000..64a8017
--- /dev/null
+++ b/.clippy.toml
@@ -0,0 +1 @@
+enum-variant-size-threshold = 500
diff --git a/Cargo.lock b/Cargo.lock
index 43b3a98..0a4636f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,40 +1,39 @@
[[package]]
-name = "bitflags"
-version = "1.0.3"
+name = "autocfg"
+version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "dtoa"
-version = "0.4.2"
+name = "bitflags"
+version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "fuchsia-zircon"
-version = "0.3.3"
+name = "cloudabi"
+version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
-name = "fuchsia-zircon-sys"
-version = "0.3.3"
+name = "fuchsia-cprng"
+version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itoa"
-version = "0.4.1"
+version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
-version = "0.2.42"
+version = "0.2.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
-version = "0.4.6"
+version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -42,25 +41,119 @@ dependencies = [
[[package]]
name = "quote"
-version = "0.6.3"
+version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
-version = "0.4.2"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_jitter 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rand_hc"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_isaac"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_jitter"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_os"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_pcg"
+version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rand_xorshift"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rdrand"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
-version = "0.1.40"
+version = "0.1.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -68,53 +161,79 @@ name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc_version"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "ryu"
+version = "0.2.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "semver"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
+name = "semver-parser"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "serde"
-version = "1.0.66"
+version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
-version = "1.0.66"
+version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_json"
-version = "1.0.20"
+version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "space"
version = "0.1.0"
dependencies = [
- "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_json 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
-version = "0.14.2"
+version = "0.15.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -123,17 +242,17 @@ name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
- "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
-version = "0.4.6"
+version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -143,7 +262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
-version = "0.3.5"
+version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -161,24 +280,38 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
-"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
-"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
-"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
-"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
-"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
-"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
-"checksum proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "effdb53b25cdad54f8f48843d67398f7ef2e14f12c1b4cb4effc549a6462a4d6"
-"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
-"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
-"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
+"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
+"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
+"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
+"checksum fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31"
+"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
+"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047"
+"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915"
+"checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
+"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
+"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
+"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
+"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
+"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
+"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
+"checksum rand_jitter 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "080723c6145e37503a2224f801f252e14ac5531cb450f4502698542d188cb3c0"
+"checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d"
+"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05"
+"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
+"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
+"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
-"checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95"
-"checksum serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "0a90213fa7e0f5eac3f7afe2d5ff6b088af515052cc7303bd68c7e3b91a3fb79"
-"checksum serde_json 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "fc97cccc2959f39984524026d760c08ef0dd5f0f5948c8d31797dbfae458c875"
-"checksum syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c67da57e61ebc7b7b6fff56bb34440ca3a83db037320b0507af4c10368deda7d"
+"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
+"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
+"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
+"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
+"checksum serde 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "534b8b91a95e0f71bca3ed5824752d558da048d4248c91af873b63bd60519752"
+"checksum serde_derive 1.0.85 (registry+https://github.com/rust-lang/crates.io-index)" = "a915306b0f1ac5607797697148c223bedeaa36bcc2e28a01441cd638cc6567b4"
+"checksum serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "27dce848e7467aa0e2fcaf0a413641499c0b745452aaca1194d24dedde9e13c9"
+"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
-"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
+"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
-"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
+"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
index cbb856f..4d661cc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,11 +2,12 @@
name = "space"
version = "0.1.0"
authors = ["tom barrett <spalf0@gmail.com>"]
+edition = "2018"
[dependencies]
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
-termion = "1.5.1"
-rand = "0.4"
+termion = "*"
+rand = "0.6"
toml = "0.4"
diff --git a/src/bin/client.rs b/src/bin/client.rs
index 3353e87..e452492 100644
--- a/src/bin/client.rs
+++ b/src/bin/client.rs
@@ -1,29 +1,29 @@
+extern crate serde_json;
extern crate space;
extern crate toml;
-extern crate serde_json;
#[macro_use]
extern crate serde_derive;
-use std::io;
use std::fs::File;
-use std::io::BufReader;
+use std::io;
use std::io::prelude::*;
+use std::io::BufReader;
use std::net::TcpStream;
-use space::modules::types::ModuleType;
-use space::client::mining::client_mining;
-use space::client::engines::client_engines;
-use space::client::refinery::client_refinery;
+use space::client::construction::client_construction;
use space::client::dashboard::client_dashboard;
+use space::client::engines::client_engines;
+use space::client::mining::client_mining;
use space::client::navigation::client_navigation;
-use space::client::construction::client_construction;
+use space::client::refinery::client_refinery;
+use space::modules::types::ModuleType;
#[derive(Debug, Deserialize)]
struct Config {
- username : Option<String>,
- password : Option<String>,
- server : Option<String>,
+ username: Option<String>,
+ password: Option<String>,
+ server: Option<String>,
}
fn main() {
@@ -35,12 +35,12 @@ fn main() {
Ok(mut config_file) => {
let mut config_string = String::new();
config_file.read_to_string(&mut config_string).unwrap();
- let config : Config = toml::from_str(&config_string).unwrap();
+ let config: Config = toml::from_str(&config_string).unwrap();
server = config.server.unwrap();
name = config.username.unwrap();
send = name.clone() + ":" + &config.password.unwrap() + "\n";
- },
+ }
Err(_err) => {
println!("Ship Name:");
io::stdin().read_line(&mut name).expect("Failed");
@@ -52,17 +52,17 @@ fn main() {
server = "localhost:6000".to_string();
send = name.clone() + ":" + &password;
- },
+ }
}
let mut stream = TcpStream::connect(&server).unwrap();
let mut buff_r = BufReader::new(stream.try_clone().unwrap());
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let modules : Vec<ModuleType> = serde_json::from_str(&recv.replace("\n","")).unwrap();
+ let modules: Vec<ModuleType> = serde_json::from_str(&recv.replace("\n", "")).unwrap();
println!("Choose your module:");
for (i, module) in modules.iter().enumerate() {
@@ -71,10 +71,13 @@ fn main() {
let mut choice = String::new();
io::stdin().read_line(&mut choice).expect("Failed");
- let module_type = modules.into_iter().nth(choice.replace("\n", "").parse::<usize>().unwrap()).unwrap();
+ let module_type = modules
+ .into_iter()
+ .nth(choice.replace("\n", "").parse::<usize>().unwrap())
+ .unwrap();
let send = serde_json::to_string(&module_type).unwrap() + "\n";
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
match module_type {
ModuleType::Dashboard => client_dashboard(buff_r),
diff --git a/src/bin/server.rs b/src/bin/server.rs
index e20acf6..ea961b7 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -1,16 +1,16 @@
extern crate space;
+use std::collections::HashMap;
+use std::net::TcpListener;
use std::thread::sleep;
use std::time::Duration;
-use std::net::TcpListener;
-use std::collections::HashMap;
use space::mass::Mass;
use space::math::rand_name;
use space::server::connection::ServerConnection;
fn populate() -> HashMap<String, Mass> {
- let mut masses : HashMap<String, Mass> = HashMap::new();
+ let mut masses: HashMap<String, Mass> = HashMap::new();
for _ in 0..10 {
masses.insert(rand_name(), Mass::new_astroid());
@@ -25,23 +25,23 @@ fn main() {
let mut masses = populate();
- let mut connections : Vec<ServerConnection> = Vec::new();
+ let mut connections: Vec<ServerConnection> = Vec::new();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
let new_connection = ServerConnection::new(stream, &mut masses);
- let exists = connections.iter().position(|connection|
- connection.name == new_connection.name &&
- connection.module_type == new_connection.module_type);
- match exists {
- Some(index) => { connections.remove(index); },
- _ => (),
+ let exists = connections.iter().position(|connection| {
+ connection.name == new_connection.name
+ && connection.module_type == new_connection.module_type
+ });
+ if let Some(index) = exists {
+ connections.remove(index);
}
connections.push(new_connection);
- },
+ }
_ => {
- for i in 0..connections.len() {
- connections[i].process(&mut masses);
+ for connection in &mut connections {
+ connection.process(&mut masses);
}
for mass in masses.values_mut() {
@@ -49,7 +49,7 @@ fn main() {
}
sleep(Duration::from_millis(100));
- },
+ }
}
}
}
diff --git a/src/client/construction.rs b/src/client/construction.rs
index 7a316c6..b034b77 100644
--- a/src/client/construction.rs
+++ b/src/client/construction.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufReader, BufRead};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::construction::ConstructionData;
-use modules::construction::ConstructionStatus;
+use crate::modules::construction::ConstructionStatus;
+use crate::server::construction::ConstructionData;
-pub fn client_construction(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,32 +18,37 @@ pub fn client_construction(mut stream : TcpStream, mut buff_r : BufReader<TcpStr
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let data : ConstructionData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+ let data: ConstructionData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
write!(stdout, "{}", termion::clear::All).unwrap();
- let clear = termion::cursor::Goto(1,1);
+ let clear = termion::cursor::Goto(1, 1);
- match data.has_refined {
- true => match data.status {
- ConstructionStatus::None => write!(stdout, "{}Press c to create a refinery.", clear).unwrap(),
- _ => write!(stdout, "{}Press c to cancel..", clear).unwrap(),
- },
- false => write!(stdout, "{}You need 5 refined minerals to create a refinery.", clear).unwrap(),
+ if data.has_refined {
+ match data.status {
+ ConstructionStatus::None => {
+ write!(stdout, "{}Press c to create a refinery.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press c to cancel..", clear).unwrap(),
+ }
+ } else {
+ write!(
+ stdout,
+ "{}You need 5 refined minerals to create a refinery.",
+ clear
+ )
+ .unwrap();
}
- match stdin.next() {
- Some(c) => {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ if let Some(c) = stdin.next() {
+ let c = c.unwrap();
+ let mut send = String::new();
+ send.push(c as char);
+ if send.as_bytes() == b"q" {
+ break;
}
- None => ()
+ send.push_str("\n");
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/dashboard.rs b/src/client/dashboard.rs
index 5815ee2..ec1fd4b 100644
--- a/src/client/dashboard.rs
+++ b/src/client/dashboard.rs
@@ -1,14 +1,14 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
-use std::io::{BufRead, BufReader, stdout, Write, Read};
-use self::termion::raw::IntoRawMode;
use self::termion::async_stdin;
+use self::termion::raw::IntoRawMode;
+use std::io::{stdout, BufRead, BufReader, Read, Write};
+use std::net::TcpStream;
-use mass::Mass;
+use crate::mass::Mass;
-pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
+pub fn client_dashboard(mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -16,15 +16,19 @@ pub fn client_dashboard(mut buff_r : BufReader<TcpStream>) {
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let ship : Mass = serde_json::from_str(&recv).unwrap();
+ let ship: Mass = serde_json::from_str(&recv).unwrap();
- write!(stdout, "{}{}{:?}",
- termion::clear::All,
- termion::cursor::Goto(1,1),
- ship).unwrap();
+ write!(
+ stdout,
+ "{}{}{:?}",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1),
+ ship
+ )
+ .unwrap();
if let Some(c) = stdin.next() {
- let c = c.unwrap() as char;
+ let c = c.unwrap() as char;
if c == 'q' {
break;
}
diff --git a/src/client/engines.rs b/src/client/engines.rs
index 9b2d314..8f83998 100644
--- a/src/client/engines.rs
+++ b/src/client/engines.rs
@@ -1,15 +1,15 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::thread::sleep;
-use std::time::Duration;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{Read, Write, stdout};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
+use std::thread::sleep;
+use std::time::Duration;
-pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -19,15 +19,31 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
buff_r.read_line(&mut recv).unwrap();
let has_target = serde_json::from_str(&recv.replace("\n", "")).unwrap();
- write!(stdout, "{}{}use numpad to freely move\n", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
+ writeln!(
+ stdout,
+ "{}{}use numpad to freely move",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1)
+ )
+ .unwrap();
write!(stdout, "{}+ : speedup", termion::cursor::Goto(1, 2)).unwrap();
write!(stdout, "{}- : slowdown", termion::cursor::Goto(1, 3)).unwrap();
write!(stdout, "{}s : stop", termion::cursor::Goto(1, 4)).unwrap();
write!(stdout, "{}q : quit", termion::cursor::Goto(1, 5)).unwrap();
if has_target {
- write!(stdout, "{}c : mimic targets velocity vector", termion::cursor::Goto(1, 6)).unwrap();
- write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1, 7)).unwrap();
+ write!(
+ stdout,
+ "{}c : mimic targets velocity vector",
+ termion::cursor::Goto(1, 6)
+ )
+ .unwrap();
+ write!(
+ stdout,
+ "{}t : accelerate torwards target",
+ termion::cursor::Goto(1, 7)
+ )
+ .unwrap();
}
if let Some(c) = stdin.next() {
@@ -38,7 +54,7 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/mining.rs b/src/client/mining.rs
index 221f7ce..5515f3a 100644
--- a/src/client/mining.rs
+++ b/src/client/mining.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufReader, BufRead};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::mining::MiningData;
-use modules::mining::MiningStatus;
+use crate::modules::mining::MiningStatus;
+use crate::server::mining::MiningData;
-pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,24 +18,34 @@ pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let data : MiningData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+ let data: MiningData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
write!(stdout, "{}", termion::clear::All).unwrap();
- let clear = termion::cursor::Goto(1,1);
+ let clear = termion::cursor::Goto(1, 1);
- match data.has_astroid_target {
- true => match data.is_within_range {
- true => match data.astroid_has_minerals {
- true => match data.status {
- MiningStatus::None => write!(stdout, "{}Press F to begin mining.", clear).unwrap(),
- _ => write!(stdout, "{}Press F to stop mining.", clear).unwrap(),
- },
- false => write!(stdout, "{}Astroid has ran out of minerals.", clear).unwrap(),
+ if data.has_astroid_target {
+ if data.is_within_range {
+ if data.astroid_has_minerals {
+ match data.status {
+ MiningStatus::None => {
+ write!(stdout, "{}Press F to begin mining.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press F to stop mining.", clear).unwrap(),
+ };
+ } else {
+ write!(stdout, "{}Astroid has ran out of minerals.", clear).unwrap();
}
- false => write!(stdout, "{}Astroid must be within range of {}.", clear, data.range).unwrap(),
- },
- false => write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap(),
+ } else {
+ write!(
+ stdout,
+ "{}Astroid must be within range of {}.",
+ clear, data.range
+ )
+ .unwrap();
+ }
+ } else {
+ write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap();
}
if let Some(c) = stdin.next() {
@@ -46,7 +56,7 @@ pub fn client_mining(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>)
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/client/mod.rs b/src/client/mod.rs
index 421a394..530e2de 100644
--- a/src/client/mod.rs
+++ b/src/client/mod.rs
@@ -1,6 +1,6 @@
-pub mod mining;
-pub mod engines;
-pub mod refinery;
+pub mod construction;
pub mod dashboard;
+pub mod engines;
+pub mod mining;
pub mod navigation;
-pub mod construction;
+pub mod refinery;
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 34e1b7a..0ab25c6 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -1,18 +1,18 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
-use std::collections::BTreeMap;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::collections::BTreeMap;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use math::distance;
-use mass::{Mass, MassType};
-use modules::navigation::Navigation;
+use crate::mass::{Mass, MassType};
+use crate::math::distance;
+use crate::modules::navigation::Navigation;
-pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : BufReader<TcpStream>){
+pub fn client_navigation(name: String, mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -20,42 +20,48 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let mut within_range : BTreeMap<String, Mass> = serde_json::from_str(&recv).unwrap();
+ let mut within_range: BTreeMap<String, Mass> = serde_json::from_str(&recv).unwrap();
- write!(stdout, "{}{}Targets:",
- termion::clear::All,
- termion::cursor::Goto(1,1)).unwrap();
+ write!(
+ stdout,
+ "{}{}Targets:",
+ termion::clear::All,
+ termion::cursor::Goto(1, 1)
+ )
+ .unwrap();
let ship = within_range.remove(&name).unwrap();
- if let MassType::Ship{ref navigation, ..} = ship.mass_type {
+ if let MassType::Ship { ref navigation, .. } = ship.mass_type {
let navigation = navigation.clone().unwrap();
for (i, (mass_name, mass)) in within_range.iter().enumerate() {
let target_data = get_target_status(&navigation, &mass_name);
- write!(stdout, "{}{}) {} ({:.2}, {:.2}, {:.2}) Distance : {:.2} {}",
- termion::cursor::Goto(1, 2 + i as u16),
- i,
- mass_name,
- mass.position.0,
- mass.position.1,
- mass.position.2,
- distance(mass.position, ship.position),
- target_data
- ).unwrap();
+ write!(
+ stdout,
+ "{}{}) {} ({:.2}, {:.2}, {:.2}) Distance : {:.2} {}",
+ termion::cursor::Goto(1, 2 + i as u16),
+ i,
+ mass_name,
+ mass.position.0,
+ mass.position.1,
+ mass.position.2,
+ distance(mass.position, ship.position),
+ target_data
+ )
+ .unwrap();
}
if let Some(c) = stdin.next() {
let c = c.unwrap() as char;
if c == 'q' {
break;
- }
- else {
+ } else {
let i = c.to_digit(10).unwrap() as usize;
if i < within_range.len() {
let mut send = String::new();
send.push_str(within_range.iter().nth(i).unwrap().0);
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
}
}
@@ -64,14 +70,15 @@ pub fn client_navigation(name : String, mut stream : TcpStream, mut buff_r : Buf
}
}
-fn get_target_status(navigation : &Navigation, mass_name : &String) -> String {
+fn get_target_status(navigation: &Navigation, mass_name: &str) -> String {
match navigation.target_name.clone() {
Some(name) => {
- match &name == mass_name {
- true => serde_json::to_string(&navigation.status).unwrap(),
- false => String::new()
+ if name == mass_name {
+ serde_json::to_string(&navigation.status).unwrap()
+ } else {
+ String::new()
}
- },
+ }
_ => String::new(),
}
}
diff --git a/src/client/refinery.rs b/src/client/refinery.rs
index 013172d..caceda7 100644
--- a/src/client/refinery.rs
+++ b/src/client/refinery.rs
@@ -1,16 +1,16 @@
-extern crate termion;
extern crate serde_json;
+extern crate termion;
-use std::net::TcpStream;
use self::termion::async_stdin;
-use std::io::{BufRead, BufReader};
-use std::io::{stdout, Read, Write};
use self::termion::raw::IntoRawMode;
+use std::io::{stdout, Read, Write};
+use std::io::{BufRead, BufReader};
+use std::net::TcpStream;
-use server::refinery::RefineryData;
-use modules::refinery::RefineryStatus;
+use crate::modules::refinery::RefineryStatus;
+use crate::server::refinery::RefineryData;
-pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>) {
+pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
@@ -18,21 +18,24 @@ pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>
loop {
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let data : RefineryData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
+ let data: RefineryData = serde_json::from_str(&recv.replace("\n", "")).unwrap();
write!(stdout, "{}", termion::clear::All).unwrap();
- let clear = termion::cursor::Goto(1,1);
-
- match data.has_minerals {
- true => match data.status {
- RefineryStatus::None => write!(stdout, "{}Press R to begin refining.", clear).unwrap(),
- _ => write!(stdout, "{}Press R to stop refining.", clear).unwrap(),
- },
- false => write!(stdout, "{}You have no refinable minerals.", clear).unwrap(),
+ let clear = termion::cursor::Goto(1, 1);
+
+ if data.has_minerals {
+ match data.status {
+ RefineryStatus::None => {
+ write!(stdout, "{}Press R to begin refining.", clear).unwrap()
+ }
+ _ => write!(stdout, "{}Press R to stop refining.", clear).unwrap(),
+ };
+ } else {
+ write!(stdout, "{}You have no refinable minerals.", clear).unwrap();
}
- if let Some(c) = stdin.next() {
+ if let Some(c) = stdin.next() {
let c = c.unwrap();
let mut send = String::new();
send.push(c as char);
@@ -40,7 +43,7 @@ pub fn client_refinery(mut stream : TcpStream, mut buff_r : BufReader<TcpStream>
break;
}
send.push_str("\n");
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
}
stdout.flush().unwrap();
diff --git a/src/item.rs b/src/item.rs
index af5c2f8..c51b1a2 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -1,23 +1,18 @@
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Item {
- pub name : String,
- pub size : usize,
+ pub name: String,
+ pub size: usize,
}
impl Item {
- pub fn new(name : &str, size : usize) -> Item {
+ pub fn new(name: &str, size: usize) -> Item {
Item {
- name : String::from(name),
- size : size,
+ name: String::from(name),
+ size,
}
}
pub fn is_mineral(&self) -> bool {
- if self.name == "Mineral" {
- true
- }
- else {
- false
- }
+ self.name == "Mineral"
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 0c917f7..406bab9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,10 @@
#[macro_use]
extern crate serde_derive;
-pub mod mass;
+pub mod client;
pub mod item;
+pub mod mass;
pub mod math;
-pub mod client;
-pub mod server;
pub mod modules;
+pub mod server;
pub mod storage;
diff --git a/src/mass.rs b/src/mass.rs
index f09685f..db97d49 100644
--- a/src/mass.rs
+++ b/src/mass.rs
@@ -1,44 +1,44 @@
extern crate rand;
-use self::rand::distributions::Range;
-use self::rand::distributions::Sample;
-
-use item::Item;
-use storage::Storage;
-use modules::mining::Mining;
-use modules::engines::Engines;
-use modules::types::ModuleType;
-use modules::refinery::Refinery;
-use modules::dashboard::Dashboard;
-use modules::navigation::Navigation;
-use modules::construction::Construction;
+use self::rand::distributions::Uniform;
+use self::rand::Rng;
+
+use crate::item::Item;
+use crate::modules::construction::Construction;
+use crate::modules::dashboard::Dashboard;
+use crate::modules::engines::Engines;
+use crate::modules::mining::Mining;
+use crate::modules::navigation::Navigation;
+use crate::modules::refinery::Refinery;
+use crate::modules::types::ModuleType;
+use crate::storage::Storage;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Mass {
- pub mass_type : MassType,
- pub position : (f64, f64, f64),
- pub velocity : (f64, f64, f64),
+ pub mass_type: MassType,
+ pub position: (f64, f64, f64),
+ pub velocity: (f64, f64, f64),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum MassType {
Ship {
- storage : Storage,
- mining : Option<Mining>,
- engines : Option<Engines>,
- refinery : Option<Refinery>,
- dashboard : Option<Dashboard>,
- navigation : Option<Navigation>,
+ storage: Storage,
+ mining: Option<Mining>,
+ engines: Option<Engines>,
+ refinery: Option<Refinery>,
+ dashboard: Option<Dashboard>,
+ navigation: Option<Navigation>,
construction: Option<Construction>,
},
Astroid {
- resources : Storage,
+ resources: Storage,
},
Item {
- item : Item,
+ item: Item,
},
Station {
- module_type : ModuleType,
+ module_type: ModuleType,
},
}
@@ -46,64 +46,73 @@ impl Mass {
pub fn new_astroid() -> Mass {
let mut rng = rand::thread_rng();
- let mut pr = Range::new(-50.0, 50.0);
- let position = (pr.sample(&mut rng), pr.sample(&mut rng), pr.sample(&mut rng));
+ let p_range = Uniform::new(-50.0, 50.0);
+ let position = (
+ rng.sample(p_range),
+ rng.sample(p_range),
+ rng.sample(p_range),
+ );
- let mut vr = Range::new(-0.5, 0.5);
- let velocity = (vr.sample(&mut rng), vr.sample(&mut rng), vr.sample(&mut rng));
+ let v_range = Uniform::new(-0.5, 0.5);
+ let velocity = (
+ rng.sample(v_range),
+ rng.sample(v_range),
+ rng.sample(v_range),
+ );
- let mut rr = Range::new(0, 20);
let mut resources = Vec::new();
- for _ in 0..rr.sample(&mut rng) {
+ for _ in 0..rng.gen_range(0, 20) {
resources.push(Item::new("Mineral", 1));
}
let astroid = MassType::Astroid {
- resources : Storage::new(resources),
+ resources: Storage::new(resources),
};
Mass {
- mass_type : astroid,
- position : position,
- velocity : velocity,
+ mass_type: astroid,
+ position,
+ velocity,
}
}
pub fn new_ship() -> Mass {
let ship = MassType::Ship {
- mining : Some(Mining::new()),
- engines : Some(Engines::new()),
- refinery : Some(Refinery::new()),
- dashboard : Some(Dashboard::new()),
- navigation : Some(Navigation::new()),
+ mining: Some(Mining::new()),
+ engines: Some(Engines::new()),
+ refinery: Some(Refinery::new()),
+ dashboard: Some(Dashboard::new()),
+ navigation: Some(Navigation::new()),
construction: Some(Construction::new()),
- storage : Storage::new(Vec::new()),
+ storage: Storage::new(Vec::new()),
};
Mass {
- mass_type : ship,
- position : (0.0, 0.0, 0.0),
- velocity : (0.0, 0.0, 0.0),
+ mass_type: ship,
+ position: (0.0, 0.0, 0.0),
+ velocity: (0.0, 0.0, 0.0),
}
}
- pub fn new_item(item : Item, position : (f64, f64, f64), velocity : (f64, f64, f64)) -> Mass {
+ pub fn new_item(item: Item, position: (f64, f64, f64), velocity: (f64, f64, f64)) -> Mass {
Mass {
- mass_type : MassType::Item{item : item},
- position : position,
- velocity : velocity,
+ mass_type: MassType::Item { item },
+ position,
+ velocity,
}
}
- pub fn new_station(module_type : ModuleType, position : (f64, f64, f64), velocity : (f64, f64, f64)) -> Mass {
- let mass_type = MassType::Station {
- module_type : module_type
- };
+ pub fn new_station(
+ module_type: ModuleType,
+ position: (f64, f64, f64),
+ velocity: (f64, f64, f64),
+ ) -> Mass {
+ let mass_type = MassType::Station { module_type };
Mass {
- mass_type : mass_type,
- position : position,
- velocity : velocity,
+ mass_type,
+ position,
+ velocity,
}
}
@@ -120,15 +129,20 @@ impl Mass {
pub fn process(&mut self) {
let mut acceleration = (0.0, 0.0, 0.0);
- match self.mass_type {
- MassType::Ship{ref mut navigation, ref mut engines, ref mut mining, ref mut refinery, ref mut construction, ..} => {
- mining.as_mut().unwrap().process();
- refinery.as_mut().unwrap().process();
- navigation.as_mut().unwrap().process();
- construction.as_mut().unwrap().process();
- acceleration = engines.as_mut().unwrap().recv_acceleration();
- },
- _ => (),
+ if let MassType::Ship {
+ ref mut navigation,
+ ref mut engines,
+ ref mut mining,
+ ref mut refinery,
+ ref mut construction,
+ ..
+ } = self.mass_type
+ {
+ mining.as_mut().unwrap().process();
+ refinery.as_mut().unwrap().process();
+ navigation.as_mut().unwrap().process();
+ construction.as_mut().unwrap().process();
+ acceleration = engines.as_mut().unwrap().recv_acceleration();
}
self.accelerate(acceleration);
self.position.0 += self.velocity.0;
@@ -136,7 +150,7 @@ impl Mass {
self.position.2 += self.velocity.2;
}
- pub fn accelerate(&mut self, acceleration : (f64, f64, f64)) {
+ pub fn accelerate(&mut self, acceleration: (f64, f64, f64)) {
self.velocity.0 += acceleration.0;
self.velocity.1 += acceleration.1;
self.velocity.2 += acceleration.2;
@@ -144,31 +158,39 @@ impl Mass {
pub fn has_minerals(&self) -> bool {
match self.mass_type {
- MassType::Ship{ref storage, ..} => storage.has_minerals(),
- MassType::Astroid{ref resources, ..} => resources.has_minerals(),
+ MassType::Ship { ref storage, .. } => storage.has_minerals(),
+ MassType::Astroid { ref resources, .. } => resources.has_minerals(),
_ => false,
}
}
pub fn refined_count(&self) -> usize {
match self.mass_type {
- MassType::Ship{ref storage, ..} => storage.refined_count(),
+ MassType::Ship { ref storage, .. } => storage.refined_count(),
_ => 0,
}
}
- pub fn take(&mut self, name : &str) -> Option<Item> {
+ pub fn take(&mut self, name: &str) -> Option<Item> {
match self.mass_type {
- MassType::Ship{ref mut storage, ..} => storage.take(name),
- MassType::Astroid{ref mut resources, ..} => resources.take(name),
+ MassType::Ship {
+ ref mut storage, ..
+ } => storage.take(name),
+ MassType::Astroid {
+ ref mut resources, ..
+ } => resources.take(name),
_ => None,
}
}
- pub fn give(&mut self, item : Item) -> bool {
+ pub fn give(&mut self, item: Item) -> bool {
match self.mass_type {
- MassType::Ship{ref mut storage, ..} => storage.give(item),
- MassType::Astroid{ref mut resources, ..} => resources.give(item),
+ MassType::Ship {
+ ref mut storage, ..
+ } => storage.give(item),
+ MassType::Astroid {
+ ref mut resources, ..
+ } => resources.give(item),
_ => false,
}
}
diff --git a/src/math.rs b/src/math.rs
index 127d4b4..689ee65 100644
--- a/src/math.rs
+++ b/src/math.rs
@@ -1,11 +1,16 @@
extern crate rand;
+use self::rand::distributions::Alphanumeric;
use self::rand::Rng;
+use std::iter::repeat;
-pub fn distance(l0 : (f64, f64, f64), l1 : (f64, f64, f64)) -> f64 {
- (((l1.0-l0.0).powf(2.0) + (l1.1-l0.1).powf(2.0) + (l1.2-l0.2).powf(2.0))).sqrt()
+pub fn distance(l0: (f64, f64, f64), l1: (f64, f64, f64)) -> f64 {
+ ((l1.0 - l0.0).powf(2.0) + (l1.1 - l0.1).powf(2.0) + (l1.2 - l0.2).powf(2.0)).sqrt()
}
pub fn rand_name() -> String {
- rand::thread_rng().gen_ascii_chars().take(8).collect()
+ repeat(())
+ .map(|()| rand::thread_rng().sample(Alphanumeric))
+ .take(8)
+ .collect()
}
diff --git a/src/modules/construction.rs b/src/modules/construction.rs
index 46ddbb1..f55a2fb 100644
--- a/src/modules/construction.rs
+++ b/src/modules/construction.rs
@@ -1,5 +1,5 @@
+use crate::modules::types::ModuleType;
use std::time::SystemTime;
-use modules::types::ModuleType;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ConstructionStatus {
@@ -8,26 +8,32 @@ pub enum ConstructionStatus {
Constructed,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for ConstructionStatus {
+ fn default() -> Self {
+ ConstructionStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Construction {
- pub status : ConstructionStatus,
- construction : Option<ModuleType>,
- time : u64,
- start : Option<SystemTime>,
+ pub status: ConstructionStatus,
+ construction: Option<ModuleType>,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Construction {
pub fn new() -> Construction {
Construction {
- status : ConstructionStatus::None,
- construction : None,
- time : 5,
- start : None,
+ status: ConstructionStatus::None,
+ construction: None,
+ time: 5,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.start = Some(SystemTime::now());
self.status = ConstructionStatus::Constructed;
diff --git a/src/modules/dashboard.rs b/src/modules/dashboard.rs
index e7f739b..acc1fb8 100644
--- a/src/modules/dashboard.rs
+++ b/src/modules/dashboard.rs
@@ -1,4 +1,4 @@
-#[derive(Serialize, Deserialize, Debug, Clone)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Dashboard {}
impl Dashboard {
diff --git a/src/modules/engines.rs b/src/modules/engines.rs
index 4741a03..a930847 100644
--- a/src/modules/engines.rs
+++ b/src/modules/engines.rs
@@ -1,14 +1,14 @@
-use mass::Mass;
+use crate::mass::Mass;
-#[derive(Serialize, Deserialize, Debug, Clone)]
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Engines {
- acceleration : (f64, f64, f64),
+ acceleration: (f64, f64, f64),
}
impl Engines {
pub fn new() -> Engines {
Engines {
- acceleration : (0.0, 0.0, 0.0)
+ acceleration: (0.0, 0.0, 0.0),
}
}
@@ -18,7 +18,7 @@ impl Engines {
acceleration
}
- pub fn give_client_data(&mut self, ship : &Mass, target : Option<&Mass>, data : String) {
+ pub fn give_client_data(&mut self, ship: &Mass, target: Option<&Mass>, data: String) {
let mut acceleration = (0.0, 0.0, 0.0);
match data.as_bytes() {
b"5\n" => acceleration.0 += 0.1,
@@ -29,46 +29,38 @@ impl Engines {
b"6\n" => acceleration.2 -= 0.1,
b"+\n" => {
let m_v = ship.velocity;
- acceleration = (m_v.0 * 0.05,
- m_v.1 * 0.05,
- m_v.2 * 0.05);
- },
+ acceleration = (m_v.0 * 0.05, m_v.1 * 0.05, m_v.2 * 0.05);
+ }
b"-\n" => {
let m_v = ship.velocity;
- acceleration = (-1.0 * m_v.0 * 0.05,
- -1.0 * m_v.1 * 0.05,
- -1.0 * m_v.2 * 0.05);
- },
+ acceleration = (
+ -1.0 * m_v.0 * 0.05,
+ -1.0 * m_v.1 * 0.05,
+ -1.0 * m_v.2 * 0.05,
+ );
+ }
b"s\n" => {
let m_v = ship.velocity;
- acceleration = (-1.0 * m_v.0,
- -1.0 * m_v.1,
- -1.0 * m_v.2);
- },
+ acceleration = (-1.0 * m_v.0, -1.0 * m_v.1, -1.0 * m_v.2);
+ }
b"c\n" => {
- match target {
- Some(target) => {
- let d_v = target.velocity;
- let m_v = ship.velocity;
- acceleration = (d_v.0 - m_v.0,
- d_v.1 - m_v.1,
- d_v.2 - m_v.2);
- },
- None => (),
+ if let Some(target) = target {
+ let d_v = target.velocity;
+ let m_v = ship.velocity;
+ acceleration = (d_v.0 - m_v.0, d_v.1 - m_v.1, d_v.2 - m_v.2);
}
- },
+ }
b"t\n" => {
- match target {
- Some(target) => {
- let d_p = target.position;
- let m_p = ship.position;
- acceleration = ((d_p.0 - m_p.0) * 0.01,
- (d_p.1 - m_p.1) * 0.01,
- (d_p.2 - m_p.2) * 0.01);
- },
- None => (),
+ if let Some(target) = target {
+ let d_p = target.position;
+ let m_p = ship.position;
+ acceleration = (
+ (d_p.0 - m_p.0) * 0.01,
+ (d_p.1 - m_p.1) * 0.01,
+ (d_p.2 - m_p.2) * 0.01,
+ );
}
- },
+ }
_ => (),
}
self.acceleration = acceleration;
diff --git a/src/modules/mining.rs b/src/modules/mining.rs
index 3c091b9..b923480 100644
--- a/src/modules/mining.rs
+++ b/src/modules/mining.rs
@@ -7,26 +7,32 @@ pub enum MiningStatus {
Mined,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for MiningStatus {
+ fn default() -> Self {
+ MiningStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Mining {
- pub range : f64,
- pub status : MiningStatus,
- time : u64,
- start : Option<SystemTime>,
+ pub range: f64,
+ pub status: MiningStatus,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Mining {
pub fn new() -> Mining {
Mining {
- range : 10.0,
- status : MiningStatus::None,
- time : 5,
- start : None,
+ range: 10.0,
+ status: MiningStatus::None,
+ time: 5,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = MiningStatus::Mined;
self.start = Some(SystemTime::now());
diff --git a/src/modules/mod.rs b/src/modules/mod.rs
index d0ffd38..3929e24 100644
--- a/src/modules/mod.rs
+++ b/src/modules/mod.rs
@@ -1,7 +1,7 @@
-pub mod types;
-pub mod mining;
-pub mod engines;
-pub mod refinery;
+pub mod construction;
pub mod dashboard;
+pub mod engines;
+pub mod mining;
pub mod navigation;
-pub mod construction;
+pub mod refinery;
+pub mod types;
diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs
index 84f315c..11f3e94 100644
--- a/src/modules/navigation.rs
+++ b/src/modules/navigation.rs
@@ -1,8 +1,8 @@
-use std::time::SystemTime;
use std::collections::HashMap;
+use std::time::SystemTime;
-use mass::Mass;
-use math::distance;
+use crate::mass::Mass;
+use crate::math::distance;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum NavigationStatus {
@@ -11,28 +11,34 @@ pub enum NavigationStatus {
Targeted,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for NavigationStatus {
+ fn default() -> Self {
+ NavigationStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Navigation {
- pub range : f64,
- pub status : NavigationStatus,
- pub target_name : Option<String>,
- time : u64,
- start : Option<SystemTime>,
+ pub range: f64,
+ pub status: NavigationStatus,
+ pub target_name: Option<String>,
+ time: u64,
+ start: Option<SystemTime>,
}
impl Navigation {
pub fn new() -> Navigation {
Navigation {
- target_name : None,
- range : 100.0,
- status : NavigationStatus::None,
- time : 3,
- start : None,
+ target_name: None,
+ range: 100.0,
+ status: NavigationStatus::None,
+ time: 3,
+ start: None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = NavigationStatus::Targeted;
self.start = None;
@@ -40,13 +46,17 @@ impl Navigation {
}
}
- pub fn give_target(&mut self, target_name : String) {
+ pub fn give_target(&mut self, target_name: String) {
self.start = Some(SystemTime::now());
self.status = NavigationStatus::Targeting;
self.target_name = Some(target_name);
}
- pub fn verify_target(&mut self, ship_position : (f64, f64, f64), masses : &HashMap<String, Mass>) {
+ pub fn verify_target(
+ &mut self,
+ ship_position: (f64, f64, f64),
+ masses: &HashMap<String, Mass>,
+ ) {
if let Some(name) = self.target_name.clone() {
let target = masses.get(&name).unwrap();
if distance(target.position, ship_position) > self.range {
diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs
index 5100f3d..5fdc10c 100644
--- a/src/modules/refinery.rs
+++ b/src/modules/refinery.rs
@@ -7,24 +7,30 @@ pub enum RefineryStatus {
Refined,
}
-#[derive(Serialize, Deserialize, Debug, Clone)]
+impl Default for RefineryStatus {
+ fn default() -> Self {
+ RefineryStatus::None
+ }
+}
+
+#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Refinery {
- time : u64,
- start : Option<SystemTime>,
- pub status : RefineryStatus,
+ time: u64,
+ start: Option<SystemTime>,
+ pub status: RefineryStatus,
}
impl Refinery {
pub fn new() -> Refinery {
Refinery {
- time : 5,
- start : None,
- status : RefineryStatus::None,
+ time: 5,
+ start: None,
+ status: RefineryStatus::None,
}
}
pub fn process(&mut self) {
- if let Some(timer) = self.start.clone() {
+ if let Some(timer) = self.start {
if timer.elapsed().unwrap().as_secs() > self.time {
self.status = RefineryStatus::Refined;
self.start = Some(SystemTime::now());
diff --git a/src/server/connection.rs b/src/server/connection.rs
index 973c5d1..4fed2b6 100644
--- a/src/server/connection.rs
+++ b/src/server/connection.rs
@@ -1,49 +1,51 @@
extern crate serde_json;
-use std::io::BufReader;
+use std::collections::HashMap;
use std::io::prelude::*;
+use std::io::BufReader;
use std::net::TcpStream;
-use std::collections::HashMap;
-use mass::Mass;
-use modules::types::ModuleType;
+use crate::mass::Mass;
+use crate::modules::types::ModuleType;
pub struct ServerConnection {
- pub name : String,
- pub module_type : ModuleType,
- pub stream : TcpStream,
- pub buff_r : BufReader<TcpStream>,
- pub open : bool,
+ pub name: String,
+ pub module_type: ModuleType,
+ pub stream: TcpStream,
+ pub buff_r: BufReader<TcpStream>,
+ pub open: bool,
}
impl ServerConnection {
- pub fn new(mut stream : TcpStream, masses : &mut HashMap<String, Mass>) -> ServerConnection {
+ pub fn new(mut stream: TcpStream, masses: &mut HashMap<String, Mass>) -> ServerConnection {
let mut buff_r = BufReader::new(stream.try_clone().unwrap());
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let name = &recv[..recv.find(":").unwrap()];
+ let name = &recv[..recv.find(':').unwrap()];
- let ship = masses.entry(name.to_string()).or_insert(Mass::new_ship());
+ let ship = masses
+ .entry(name.to_string())
+ .or_insert_with(Mass::new_ship);
let send = serde_json::to_string(&ship.get_modules()).unwrap() + "\n";
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let module_type : ModuleType = serde_json::from_str(&recv.replace("\n","")).unwrap();
+ let module_type: ModuleType = serde_json::from_str(&recv.replace("\n", "")).unwrap();
stream.set_nonblocking(true).unwrap();
- ServerConnection {
- name : String::from(name),
- module_type : module_type,
- stream : stream,
- buff_r : buff_r,
- open : true,
+ ServerConnection {
+ name: String::from(name),
+ module_type,
+ stream,
+ buff_r,
+ open: true,
}
}
- pub fn process(&mut self, mut masses : &mut HashMap<String, Mass>) {
+ pub fn process(&mut self, mut masses: &mut HashMap<String, Mass>) {
match self.module_type {
ModuleType::Mining => self.server_mining(&mut masses),
ModuleType::Engines => self.server_engines(&mut masses),
diff --git a/src/server/construction.rs b/src/server/construction.rs
index 94a6b0f..70038ae 100644
--- a/src/server/construction.rs
+++ b/src/server/construction.rs
@@ -1,47 +1,65 @@
extern crate serde_json;
+use std::collections::HashMap;
use std::io::BufRead;
use std::io::Write;
-use std::collections::HashMap;
-use mass::{Mass, MassType};
-use modules::construction::Construction;
-use server::connection::ServerConnection;
-use modules::construction::ConstructionStatus;
-use modules::types::ModuleType;
+use crate::mass::{Mass, MassType};
+use crate::modules::construction::Construction;
+use crate::modules::construction::ConstructionStatus;
+use crate::modules::types::ModuleType;
+use crate::server::connection::ServerConnection;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ConstructionData {
- pub status : ConstructionStatus,
- pub has_refined : bool,
+ pub status: ConstructionStatus,
+ pub has_refined: bool,
}
impl ServerConnection {
- pub fn server_construction(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_construction(&mut self, masses: &mut HashMap<String, Mass>) {
let mut ship = masses.remove(&self.name).unwrap();
let ship_clone = ship.clone();
+ let mut construct = false;
- if let MassType::Ship{ref mut construction, ..} = ship.mass_type {
- let mut construction = construction.as_mut().unwrap();
+ if let MassType::Ship {
+ ref mut construction,
+ ..
+ } = ship.mass_type
+ {
+ let construction = construction.as_mut().unwrap();
let construction_data = get_construction_data(ship_clone.clone(), construction);
- if self.open {
- if self.txrx_construction(&construction_data) {
- construction.toggle();
- }
+ if self.open && self.txrx_construction(&construction_data) {
+ construction.toggle();
}
if construction_data.status == ConstructionStatus::Constructed {
- println!("inserted");
construction.take();
- masses.insert("Station".to_string(), Mass::new_station(ModuleType::Refinery, ship_clone.position, ship_clone.velocity));
+ masses.insert(
+ "Station".to_string(),
+ Mass::new_station(
+ ModuleType::Refinery,
+ ship_clone.position,
+ ship_clone.velocity,
+ ),
+ );
+ construct = true;
}
}
+ if construct {
+ ship.take("Refined Mineral");
+ ship.take("Refined Mineral");
+ ship.take("Refined Mineral");
+ ship.take("Refined Mineral");
+ ship.take("Refined Mineral");
+ }
+
masses.insert(self.name.clone(), ship);
}
- fn txrx_construction(&mut self, construction_data : &ConstructionData) -> bool {
+ fn txrx_construction(&mut self, construction_data: &ConstructionData) -> bool {
let send = serde_json::to_string(construction_data).unwrap() + "\n";
if let Err(_err) = self.stream.write(send.as_bytes()) {
self.open = false;
@@ -52,14 +70,14 @@ impl ServerConnection {
match recv.as_bytes() {
b"c\n" => {
if construction_data.has_refined {
- return true
+ return true;
}
- },
+ }
_ => {
if result == 0 {
self.open = false;
}
- },
+ }
}
}
@@ -67,14 +85,11 @@ impl ServerConnection {
}
}
-fn get_construction_data(ship : Mass, construction : &Construction) -> ConstructionData {
- let mut has_refined = false;
- if ship.refined_count() >= 5 {
- has_refined = true;
- }
+fn get_construction_data(ship: Mass, construction: &Construction) -> ConstructionData {
+ let has_refined = ship.refined_count() >= 5;
ConstructionData {
- status : construction.status.clone(),
- has_refined : has_refined,
+ status: construction.status.clone(),
+ has_refined,
}
}
diff --git a/src/server/dashboard.rs b/src/server/dashboard.rs
index d1aa8a4..981158b 100644
--- a/src/server/dashboard.rs
+++ b/src/server/dashboard.rs
@@ -1,13 +1,13 @@
extern crate serde_json;
-use std::io::Write;
use std::collections::HashMap;
+use std::io::Write;
-use mass::Mass;
-use server::connection::ServerConnection;
+use crate::mass::Mass;
+use crate::server::connection::ServerConnection;
impl ServerConnection {
- pub fn server_dashboard(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_dashboard(&mut self, masses: &mut HashMap<String, Mass>) {
if self.open {
let ship = masses.get(&self.name).unwrap();
let send = serde_json::to_string(&ship).unwrap() + "\n";
diff --git a/src/server/engines.rs b/src/server/engines.rs
index c0d4ad5..559ecd9 100644
--- a/src/server/engines.rs
+++ b/src/server/engines.rs
@@ -1,20 +1,25 @@
extern crate serde_json;
-use std::io::Write;
-use std::io::BufRead;
use std::collections::HashMap;
+use std::io::BufRead;
+use std::io::Write;
-use mass::{Mass, MassType};
-use modules::navigation::NavigationStatus;
-use server::connection::ServerConnection;
+use crate::mass::{Mass, MassType};
+use crate::modules::navigation::NavigationStatus;
+use crate::server::connection::ServerConnection;
impl ServerConnection {
- pub fn server_engines(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_engines(&mut self, masses: &mut HashMap<String, Mass>) {
if self.open {
let mut ship = masses.remove(&self.name).unwrap();
let ship_clone = ship.clone();
- if let MassType::Ship{ref mut engines, ref navigation, ..} = ship.mass_type {
+ if let MassType::Ship {
+ ref mut engines,
+ ref navigation,
+ ..
+ } = ship.mass_type
+ {
let navigation = navigation.clone().unwrap();
let engines = engines.as_mut().unwrap();
let targeted = navigation.status == NavigationStatus::Targeted;
diff --git a/src/server/mining.rs b/src/server/mining.rs
index bfe9223..6213e65 100644
--- a/src/server/mining.rs
+++ b/src/server/mining.rs
@@ -1,51 +1,51 @@
extern crate serde_json;
+use std::collections::HashMap;
use std::io::BufRead;
use std::io::Write;
-use std::collections::HashMap;
-use math::distance;
-use mass::{Mass, MassType};
-use modules::navigation::Navigation;
-use server::connection::ServerConnection;
-use modules::mining::{Mining, MiningStatus};
+use crate::mass::{Mass, MassType};
+use crate::math::distance;
+use crate::modules::mining::{Mining, MiningStatus};
+use crate::modules::navigation::Navigation;
+use crate::server::connection::ServerConnection;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MiningData {
- pub has_astroid_target : bool,
+ pub has_astroid_target: bool,
pub astroid_has_minerals: bool,
- pub is_within_range : bool,
- pub status : MiningStatus,
- pub range : f64,
+ pub is_within_range: bool,
+ pub status: MiningStatus,
+ pub range: f64,
}
impl ServerConnection {
- pub fn server_mining(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_mining(&mut self, masses: &mut HashMap<String, Mass>) {
let mut ship = masses.remove(&self.name).unwrap();
let ship_clone = ship.clone();
let mut item = None;
- if let MassType::Ship{ref mut mining, ref navigation, ..} = ship.mass_type {
- let mut mining = mining.as_mut().unwrap();
- let mut navigation = navigation.as_ref().unwrap();
+ if let MassType::Ship {
+ ref mut mining,
+ ref navigation,
+ ..
+ } = ship.mass_type
+ {
+ let mining = mining.as_mut().unwrap();
+ let navigation = navigation.as_ref().unwrap();
let mining_data = get_mining_data(ship_clone, mining, navigation, masses);
- if self.open {
- if self.txrx_mining(&mining_data) {
- mining.toggle();
- }
+ if self.open && self.txrx_mining(&mining_data) {
+ mining.toggle();
}
if !mining_data.is_within_range {
mining.off();
- }
- else {
- if mining.status == MiningStatus::Mined {
- mining.take();
- if let Some(name) = navigation.target_name.clone() {
- let target = masses.get_mut(&name).unwrap();
- item = target.take("Mineral");
- }
+ } else if mining.status == MiningStatus::Mined {
+ mining.take();
+ if let Some(name) = navigation.target_name.clone() {
+ let target = masses.get_mut(&name).unwrap();
+ item = target.take("Mineral");
}
}
}
@@ -60,7 +60,7 @@ impl ServerConnection {
masses.insert(self.name.clone(), ship);
}
- fn txrx_mining(&mut self, mining_data : &MiningData) -> bool {
+ fn txrx_mining(&mut self, mining_data: &MiningData) -> bool {
let send = serde_json::to_string(mining_data).unwrap() + "\n";
if let Err(_err) = self.stream.write(send.as_bytes()) {
self.open = false;
@@ -73,19 +73,24 @@ impl ServerConnection {
if mining_data.is_within_range {
return true;
}
- },
+ }
_ => {
if result == 0 {
self.open = false;
}
- },
+ }
}
}
false
}
}
-fn get_mining_data(ship : Mass, mining : &Mining, navigation : &Navigation, masses : &mut HashMap<String, Mass>) -> MiningData {
+fn get_mining_data(
+ ship: Mass,
+ mining: &Mining,
+ navigation: &Navigation,
+ masses: &mut HashMap<String, Mass>,
+) -> MiningData {
match navigation.target_name.clone() {
Some(name) => {
let target = masses.get(&name);
@@ -95,37 +100,36 @@ fn get_mining_data(ship : Mass, mining : &Mining, navigation : &Navigation, mass
Some(target) => {
astroid_has_minerals = target.has_minerals();
match target.mass_type {
- MassType::Astroid{..} => true,
+ MassType::Astroid { .. } => true,
_ => false,
}
- },
+ }
None => false,
};
- let is_within_range = match has_astroid_target {
- true => match target {
+ let is_within_range = if has_astroid_target {
+ match target {
Some(target) => mining.range > distance(ship.position, target.position),
_ => false,
}
- _ => false,
+ } else {
+ false
};
MiningData {
- has_astroid_target : has_astroid_target,
- astroid_has_minerals: astroid_has_minerals,
- is_within_range : is_within_range,
- range : mining.range,
- status : mining.status.clone(),
- }
- }
- _ => {
- MiningData {
- has_astroid_target : false,
- astroid_has_minerals: false,
- is_within_range : false,
- range : mining.range,
- status : mining.status.clone(),
+ has_astroid_target,
+ astroid_has_minerals,
+ is_within_range,
+ range: mining.range,
+ status: mining.status.clone(),
}
}
+ _ => MiningData {
+ has_astroid_target: false,
+ astroid_has_minerals: false,
+ is_within_range: false,
+ range: mining.range,
+ status: mining.status.clone(),
+ },
}
}
diff --git a/src/server/mod.rs b/src/server/mod.rs
index a5c359d..0fec4dc 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -1,7 +1,7 @@
-pub mod mining;
-pub mod engines;
-pub mod refinery;
-pub mod dashboard;
-pub mod navigation;
pub mod connection;
pub mod construction;
+pub mod dashboard;
+pub mod engines;
+pub mod mining;
+pub mod navigation;
+pub mod refinery;
diff --git a/src/server/navigation.rs b/src/server/navigation.rs
index 3eaaa8d..eb9095d 100644
--- a/src/server/navigation.rs
+++ b/src/server/navigation.rs
@@ -1,24 +1,30 @@
extern crate serde_json;
-use std::io::Write;
-use std::io::BufRead;
use std::collections::HashMap;
+use std::io::BufRead;
+use std::io::Write;
-use math::distance;
-use mass::{Mass, MassType};
-use server::connection::ServerConnection;
+use crate::mass::{Mass, MassType};
+use crate::math::distance;
+use crate::server::connection::ServerConnection;
impl ServerConnection {
- pub fn server_navigation(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_navigation(&mut self, masses: &mut HashMap<String, Mass>) {
let mut ship = masses.remove(&self.name).unwrap();
let ship_clone = ship.clone();
- if let MassType::Ship{ref mut navigation, ..} = ship.mass_type {
- let mut navigation = navigation.as_mut().unwrap();
+ if let MassType::Ship {
+ ref mut navigation, ..
+ } = ship.mass_type
+ {
+ let navigation = navigation.as_mut().unwrap();
navigation.verify_target(ship_clone.position, &masses);
- let mut within_range : HashMap<&String, &Mass> = masses.iter().filter(|&(_, mass)|
- distance(ship_clone.position, mass.position) < navigation.range)
- .collect();
+ let mut within_range: HashMap<&String, &Mass> = masses
+ .iter()
+ .filter(|&(_, mass)| {
+ distance(ship_clone.position, mass.position) < navigation.range
+ })
+ .collect();
within_range.insert(&self.name, &ship_clone);
if self.open {
diff --git a/src/server/refinery.rs b/src/server/refinery.rs
index eb82bb2..d4eb26b 100644
--- a/src/server/refinery.rs
+++ b/src/server/refinery.rs
@@ -1,38 +1,39 @@
extern crate serde_json;
-use std::io::Write;
-use std::io::BufRead;
use std::collections::HashMap;
+use std::io::BufRead;
+use std::io::Write;
-use item::Item;
-use mass::{Mass, MassType};
-use server::connection::ServerConnection;
-use modules::refinery::RefineryStatus;
+use crate::item::Item;
+use crate::mass::{Mass, MassType};
+use crate::modules::refinery::RefineryStatus;
+use crate::server::connection::ServerConnection;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RefineryData {
- pub has_minerals : bool,
- pub status : RefineryStatus,
+ pub has_minerals: bool,
+ pub status: RefineryStatus,
}
impl ServerConnection {
- pub fn server_refinery(&mut self, masses : &mut HashMap<String, Mass>) {
+ pub fn server_refinery(&mut self, masses: &mut HashMap<String, Mass>) {
let mut ship = masses.remove(&self.name).unwrap();
let ship_clone = ship.clone();
let mut refine = false;
- if let MassType::Ship{ref mut refinery, ..} = ship.mass_type {
- let mut refinery = refinery.as_mut().unwrap();
+ if let MassType::Ship {
+ ref mut refinery, ..
+ } = ship.mass_type
+ {
+ let refinery = refinery.as_mut().unwrap();
let refinery_data = RefineryData {
- has_minerals : ship_clone.has_minerals(),
- status : refinery.status.clone(),
+ has_minerals: ship_clone.has_minerals(),
+ status: refinery.status.clone(),
};
- if self.open {
- if self.txrx_refinery(&refinery_data) {
- refinery.toggle();
- }
+ if self.open && self.txrx_refinery(&refinery_data) {
+ refinery.toggle();
}
if !refinery_data.has_minerals {
@@ -44,7 +45,7 @@ impl ServerConnection {
refine = true;
}
}
-
+
if refine {
ship.take("Mineral");
ship.give(Item::new("Refined Mineral", 1));
@@ -53,7 +54,7 @@ impl ServerConnection {
masses.insert(self.name.clone(), ship);
}
- fn txrx_refinery(&mut self, refinery_data : &RefineryData) -> bool {
+ fn txrx_refinery(&mut self, refinery_data: &RefineryData) -> bool {
let send = serde_json::to_string(refinery_data).unwrap() + "\n";
if let Err(_err) = self.stream.write(send.as_bytes()) {
self.open = false;
@@ -64,18 +65,17 @@ impl ServerConnection {
match recv.as_bytes() {
b"R\n" => {
if refinery_data.has_minerals {
- return true
+ return true;
}
- },
+ }
_ => {
if result == 0 {
self.open = false;
}
- },
+ }
}
}
false
}
}
-
diff --git a/src/storage.rs b/src/storage.rs
index 72a3b27..f43bec4 100644
--- a/src/storage.rs
+++ b/src/storage.rs
@@ -1,30 +1,27 @@
-use item::Item;
+use crate::item::Item;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Storage {
- items : Vec<Item>,
- carrying : usize,
- capacity : usize,
+ items: Vec<Item>,
+ carrying: usize,
+ capacity: usize,
}
impl Storage {
- pub fn new(items : Vec<Item>) -> Storage {
+ pub fn new(items: Vec<Item>) -> Storage {
let mut carrying = 0;
for item in items.iter() {
carrying += item.size;
}
Storage {
- items : items,
- capacity : 10,
- carrying : carrying,
+ items,
+ capacity: 10,
+ carrying,
}
}
pub fn has_minerals(&self) -> bool {
- match self.items.iter().position(|item| item.is_mineral()) {
- Some(_) => true,
- None => false,
- }
+ self.items.iter().any(|item| item.is_mineral())
}
pub fn refined_count(&self) -> usize {
@@ -33,7 +30,7 @@ impl Storage {
items.len()
}
- pub fn take(&mut self, name : &str) -> Option<Item> {
+ pub fn take(&mut self, name: &str) -> Option<Item> {
match self.items.iter().position(|item| item.name == name) {
Some(index) => {
let item = self.items.remove(index);
@@ -44,14 +41,13 @@ impl Storage {
}
}
- pub fn give(&mut self, item : Item) -> bool {
- match self.capacity >= self.carrying + item.size {
- true => {
- self.carrying += item.size;
- self.items.push(item);
- true
- },
- false => false,
+ pub fn give(&mut self, item: Item) -> bool {
+ if self.capacity >= self.carrying + item.size {
+ self.carrying += item.size;
+ self.items.push(item);
+ true
+ } else {
+ false
}
}
}